#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	char oct[8] = {'0', '1', '2', '3', '5', '7', '8', '9'};
	int n;
	while(cin >> n, n)
	{
		vector<char> Vec;
		while(n)
		{
			Vec.push_back(oct[n % 8]);
			n /= 8;
		}
		for(int i = Vec.size() - 1; i >= 0; --i)
		{
			cout << Vec[i];
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}