#include <iostream>
using namespace std;
int main(){
	long long n,ans;
	int d[8]={0,1,2,3,5,7,8,9},tmp,f;
	while(cin>>n,n){
		ans=0;
		tmp=f=0;
		
		while(n>0){
			if(f){
				ans*=10;
				ans+=n%8;
				n/=8;
			}
			else{
				if(n%8==0)tmp++;
				else f=1;
				ans*=10;
				ans+=n%8;
				n/=8;
			}
		}
		for(;ans>0;ans/=10)cout<<d[ans%10];
		for(int i=0;i<tmp;i++)cout<<0;
		cout<<endl;
	}
	return 0;
}
