#include<iostream>

#include<vector>

using namespace std;

int main()
{
	for(;;)
	{
		int N;
		cin >> N;
		if(N == 0)
		{
			break;
		}

		vector<int> vobj;
		for(;;)
		{
			if(N <= 7)
			{
				vobj.push_back(N);
				break;
			}
			vobj.push_back(N % 8);
		
			N = N / 8;


		}

		for(int i = vobj.size() -1; i >= 0; i--)
		{
			int outputNo;
			outputNo = vobj[i];
			if(outputNo == 4)
			{
				outputNo = 5;
			}
			else if(outputNo == 5)
			{
				outputNo = 7;
			}
			else if(outputNo == 6)
			{
				outputNo = 8;
			}
			else if(outputNo == 7)
			{
				outputNo = 9;
			}
			cout << outputNo;

		}
		cout << endl;

	}



}