#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int time=0;
    int n;
    ll ans=0;
    while(cin>>n){
        ans=0;
        if(n==0)break;
        time=0;
        
        for(int i=9;i>=1;i--){
            time=0;
            while(n>=pow(8,i)){
                time++;
                if( time!=4 && time!=6 )
                    n-=pow(8,i);
                ans+=pow(10,i);
            }
        }
        for(int i=1;i<=9;i++){
            if(n==0)break;

            if(i!=4 && i!=6){
                n--;
            }
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}