#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int table[] = {0, 1, 2, 3, 5, 7, 8, 9};

int main()
{
  vector<int> num;
  int n;
  while (scanf("%d ", &n) == 1) {
    if (n == 0) {break;}
    num.clear();
    while (n > 0) {
      num.push_back(n % 8);
      n /= 8;
    }
    reverse(num.begin(), num.end());
    for (int i = 0; i < num.size(); i++) {
      printf("%d", table[num[i]]);
    }
    printf("\n");
  }
  return 0;
}