#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
typedef long long ll;

char i2c(int i) { return '0'+i; }

const char* d2o(ll a) {
  string s;
  while (a) {
    s += i2c(a % 8);
    a /= 8;
  }
  reverse(s.begin(), s.end());
  rep(i,s.size()) {
    if(s[i] == '4') s[i] = '5';
    else if(s[i] == '5') s[i] = '7';
    else if(s[i] == '6') s[i] = '8';
    else if(s[i] == '7') s[i] = '9';
  }
  return s.c_str();
}

int main() {
  //int in;
  ll in;
  while (cin>>in,in) {
    //printf("%d\n",in);
    //printf("%d\n",d2o(in));
    cout<<d2o(in)<<endl;
  }
  return 0;
}