#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	string s="01235789";
	while(1){
		cin>>n;
		if(n==0) break;
		string ans="";
		bool f=false;
		for(int i=10;i>=0;i--){
			int now=n/(int)pow((int)8,i);
			if(now!=0) f=true;
			//cout<<now<<" ";
			if(f){
				ans+=s[now];
				//cout<<s[now]<<" ";
			}
			n%=(int)pow((int)8,i);
		}
		//cout<<endl;
		o(ans);
	}
}