#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef long long LL;
typedef istringstream ISS;
typedef ostringstream OSS;

char toChar( int n ) {
    return n + '0';
}

string toSeven( LL n ) {
    string s;
    while ( n >= 8 ) {
        s += toChar( n % 8 );
        n /= 8;
    }
    s += toChar( n );
    reverse( s.begin(), s.end() );
    return s;
}

LL toNewNumber( string s ) {
    char T[8] = { '0', '1', '2', '3', '5', '7', '8', '9' };
    string t = s;
    int n = s.size();
    for ( int i = 0; i < n; ++ i ) {
        s[i] = T[ s[i] - '0' ];
    }
    ISS iss1( s );
    LL res;
    iss1 >> res;
    return res;
}

LL solve( LL n ) {
    return toNewNumber( toSeven( n ) );
}

int main() {
    LL n;
    while ( cin >> n && n ) {
        cout << solve( n ) << endl;
    }
    return 0;
}