#include <iostream>
using namespace std;

int main()
{
	unsigned long long n, m;

	cin >> n;

	while (n) {
		m = 0;
		unsigned long long i = 1;

		while (n > 0) {
			unsigned long long t = n % 8;
			if (t < 4)
				m += t * i;
			else if (t == 4)
				m += 5 * i;
			else
				m += (t + 2) * i;

			n /= 8;
			i *= 10;
		}

		cout << m << endl;

		cin >> n;
	}

	return 0;
}
