#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

const int MAX_N = 1e9+9;
vector<int> ans;

bool ok(int a) {
    while(a) {
        if(a%10 == 4 || a%10 == 6) return false;
        a /= 10;
    }
    return true;
}

int n;
string s[] = {"0", "1","2","3","5","7","8","9"};
void hoge() {
    ans.reserve(100000);
    rep(i,101) {
        if(!i) continue;
        if(ok(i)) ans.pb(i);
        // if(log10(i) == floor(log10(i))) 
    }
    cout<<endl;
    rep(i,ans.size()) {
        // if((i+1)%8==0)
        cout<<i+1<<" "<<ans[i]<<endl;
    }

}

int main() {

    while(cin>>n) {
        if(!n) break;
        string ans;
        while(n) {
            ans += s[n%8];
            n>>=3;
        }
        reverse(all(ans));
        cout<<ans<<endl;


    }

    return 0;
}