#include<vector>
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		vector<int> renew;
		while(n){
			int digit=n%8;
			if(digit>=4)	digit++;
			if(digit>=6)	digit++;
			renew.push_back(digit);
			n/=8;
		}
		for(int i=renew.size()-1;i>=0;i--)	cout<<renew[i];
		cout<<endl;
	}
	return 0;
}