#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    while (true) {
        int n;
        cin >> n;
        
        if (n==0) {
            break;
        }
        
        map<int, int> mp{{0,0}, {1,1}, {2,2}, {3,3}, {4,5}, {5,7}, {6,8}, {7,9}};
        
        int ans = 0;
        int c = 1;
        
        while (!(n<8)) {
            ans += mp[n%8]*c;
            n /= 8;
            c *= 10;
        }
        
        ans += mp[n]*c;
        
        cout << ans << endl;
    }
}
