def solve n
  result = Array.new
  while n > 0 do
    l = n % 8
    n = n / 8
    result.push(change(l))
  end
  result.reverse.join()
end

def change n
  case n
  when 0..3
    n
  when 4
    n + 1
  when 5..7
    n + 2
  end
end

while (n = $stdin.gets.to_i) != 0 do
  puts solve(n)
end