let f = function
    4 -> 5
  | 5 -> 7
  | 6 -> 8
  | 7 -> 9
  | i -> i
;;

let () =
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        let rec loop n b p =
          let m = n / 8 and
              r = n mod 8 in
          if m = 0 then
            b + (f r)*p
          else
            loop m (b + (f r)*p) (p*10)
        in
        Printf.printf "%d\n" (loop n 0 1);
        read ()
      end
  in read ()
;;