#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;


long long int d8(long long int c, int n, int d)
{
	int r2 = n % 8;
	if (r2 > 4) r2++;
	if (r2 > 3) r2++;
	c += r2 * pow(10,d - 1);
	if (n / 8 > 0)
		c = d8(c, n / 8, d + 1);
	
	return c;
}

int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		cout << d8(0, n, 1) << endl;
	}

	return 0;
}