import scala.io.StdIn.readInt

object Main extends App {
  def replace(i:Char) = 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):String = {
    val (m,r) = (n/8, n%8)
    if(m==0) (b + r*p).toString.map(c => replace(c))
    else scan(m, b+r*p, p*10)
  }

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