while true do
  n = gets.chomp.to_i
  if n==0 then
    break
  end
  s = n.to_s(8)
  for i in 0..s.length-1 do
    b = s[i].to_i
    if b >= 4 then
      if b >= 5 then
        b += 2
      else
        b += 1
      end
    end
    s[i] = b.to_s
  end
  puts s
end