#include <iostream>
#include <cmath>
using namespace std;


void solve(int n) {
  int mod = (int)pow(8.0,10.0);
  bool start = false;
  while(mod != 0) {
    int x = n / mod;
    if(x != 0) start = true;
    if(start) {
      int res = x;
      if(res >= 4) res++;
      if(res >= 6) res++;
      cout << res;
      n -= x * mod;
    }
    mod /= 8;
  }
  cout << endl;
}

int main() {
  int n;
  while(cin >> n,n) {
    solve(n);
  }
}