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

vector<int> calc(int n) {
    vector<int> a;
    while (n > 0) {
        a.push_back(n % 8);
        n /= 8;
    }
    return a;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) return 0;

        vector<int> a = calc(n);
        for (int i = a.size() - 1; i >= 0; i--) {
            if (0 <= a[i] && a[i] <= 3) {
                cout << a[i];
            } else if (a[i] == 4) {
                cout << 5;
            } else {
                cout << a[i] + 2;
            }
        }
        cout << endl;
    }
}