#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

/*
1 2 3 5 7 8 9 10 11 12 13 15 17 18 19 new
1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 
*/

string changeStr(long long n){
    long long copy = n;
    int len = -1;
    while(copy != 0){
        len++;
        copy/=10;
    }

    string str;
    long long K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

long long newRoomNumber(long long o){ //old number, new number
    long long n = 0, K = 1;
    while(o != 0){
        n+= (o % 8) * K;
        o/= 8;
        K*=10;
    }
    return n;
}

string deleteFourAndSix(string n){
    rep(i,n.size()){
        if(n[i] == '4') n[i] = '5';
        else if(n[i] == '5') n[i] = '7';
        else if(n[i] == '6') n[i] = '8';
        else if(n[i] == '7') n[i] = '9';
    }
    return n;
}

int main(){
    long long n;
    while(cin >> n, n){
        cout << deleteFourAndSix(changeStr(newRoomNumber(n))) << endl;
    }
}