#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	ll n;
	ll m;
	cin >> n;
	if(n==0) break;
	m = 0;
	int x = 1;
	while(n>0){
	    int mo = n % 8;
	    if(mo >= 5){
		m += (2 + (n % 8) )*x ;
	    }else if(mo >= 4){
		m += (1 + (n % 8))*x ;
	    }else{
		m += (n % 8)*x ;
	    }
	    x *= 10;
	    n /= 8;
	}
	cout << m << endl;
    }
    return 0;
}