#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main() {
    for(int N; cin >> N, N; ) {
        vector<int> vs;
        while(N >= 8) {
            vs.push_back(N % 8);
            N /= 8;
        }
        if(N != 0) vs.push_back(N);
        reverse(vs.begin(), vs.end());

        for(int c : vs) {
            if(c >= 4) c++;
            if(c >= 6) c++;
            cout << c;
        }
        cout << endl;
    }
}