#include <iostream>
#include <string>

using namespace std;

string convert(int n){ 
        string s = ""; 
        while(n){
                s += n%8 + '0';
                n /= 8;
        }   
        string _s = ""; 
        for(int i = s.size()-1; i >= 0; i--){
                char c = s[i];
                if(c >= '4') c++;
                if(c >= '6') c++;
                _s += c;
        }   
        return _s; 
}

int main(){
        int n;
        cin >> n;
        while(n){
                cout << convert(n) << endl;
                cin >> n;
        }   
}