#include <iostream>
using namespace std;

int main() {
    int n, m;
    string number;

    while (cin >> n, n) {
        number = "";
        while (n > 0) {
            m = n % 8;
            if (m > 4) {
                m += 2;
            }
            else if (m == 4) {
                m += 1;
            }
            number = " " + number;
            number[0] = '0' + m;
            n /= 8;
        }
        cout << number << endl;
    }
    return 0;
}