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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        char octal[16] = {};
        sprintf(octal, "%o", n);
        for (int i = 0; octal[i] != '\0'; i++) {
            if (octal[i] == '4') {
                octal[i]++;
            } else if ('5' <= octal[i] && octal[i] <= '7') {
                octal[i] += 2;
            }
        }
        cout << octal << endl;
    }
}