#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int num[] = {0, 1, 2, 3, 5, 7, 8, 9};

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        long long tmp = 1;
        long long ret = 0;
        while(n > 0){
            ret += tmp * num[n%8];
            n /= 8;
            tmp *= 10;
        }
        cout << ret << endl;
    }
}