#include <iostream>
using namespace std;

int main()
{
	int n,x;
	long long a;
	while(cin >> n, n)
	{
		a=0;
		for(int i=30; i>=0; i-=3)
		{
			a *= 10;
			x = (int)((n>>i)&7);
			x += x/4 + x/5;
			a += x;
		}
		cout << a << endl;
	}
}