#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#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()
#define MP make_pair
#define PB push_back

string o(ll n){
  string ret;
  while(n){
    ret+='0'+n%8;
    n/=8;
  }
  reverse(ret.begin(),ret.end());
  return ret;
}

main(){
  ll n;
  while(cin>>n,n){
    string str=o(n);

    rep(i,str.size()){
      if(str[i]>'4')str[i]+=2;
      else if(str[i]>'3')str[i]+=1;
    }
    cout<<str<<endl;
  }
}