#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string>
using namespace std;

void convert(string& n) {
    for (int i = 0; i < n.size(); i++) {
        switch (n[i]) {
            case '1': case '2': case '3':
                break;
            case '4':
                n[i] = '5'; 
                break;
            case '5': case '6': case '7':
                n[i] = n[i] + 2;
                break;
        }
    }
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        ostringstream ss;
        ss << oct << n;
        string ns = ss.str();
        convert(ns);
        cout << ns << endl;
    }
    return 0;
}