#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	long long s;
	while(cin >> s, s)
	{
		string ret;
		while(s)
		{
			ret+=s%8LL+'0';
			s/=8LL;
		}
		
		reverse(ret.begin(), ret.end());
		for(int i=0; i<ret.size(); i++)
		{
			int t=ret[i]-'0';
			if(t>=5) t+=2;
			else if(t>=4) t+=1;
			
			
			ret[i]=t+'0';
		}
		
		cout << ret << endl;
	}
}