import scala.io.StdIn.readInt

object Main extends App {
  def getNum(i:Int) = i match {
    case 4 => 5
    case 5 => 7
    case 6 => 8
    case 7 => 9
    case x => x
  }

  def scan(n:Int,b:Long,p:Long):Long = {
    val (m,r) = (n/8, n%8)
    if(m==0) b + getNum(r)*p
    else scan(m, b+getNum(r)*p, p*10)
  }

  Iterator.continually(readInt).takeWhile( _ != 0 ).foreach { n=>
    println(scan(n,0,1))
  }
}