def solve(res, d, n)
  t = [0, 1, 2, 3, 5, 7, 8, 9]
  if n == 0
    res
  else
    solve(res+t[n%8]*d, d*10, n/8)
  end
end
loop do
  n = gets.to_i
  if n == 0 then break end
  puts solve(0, 1, n)
end