#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>

int main() {

    while (true) {
        int n;
        std::cin >> n;

        if (n == 0) {
            break;
        }

        std::stringstream ss;
        ss << std::oct << n;
        std::string n_oct = ss.str();

        const int len = n_oct.length();

        std::string s = n_oct;
        std::replace(s.begin(), s.end(), '7', '9');
        std::replace(s.begin(), s.end(), '6', '8');
        std::replace(s.begin(), s.end(), '5', '7');
        std::replace(s.begin(), s.end(), '4', '5');

        std::cout << s << std::endl;
    }

    return 0;

}
