#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef long long ll;

int main() {
  ll n;
  while(cin>>n,n) {
    string oct;
    while (n != 0) {
      oct = string(1,'0'+n%8) + oct;
      n /= 8;
    }
    FOR(it, oct) {
      if (*it >= '5')
        (*it)++;
      if (*it >= '4')
        (*it)++;
    }
    cout << oct << endl;
  }
}