#include <iostream>

using namespace std;

int main() {
	int n, num[100];
	while (cin >> n, n) {
		int k = -1;
		do {
			num[++k] = n % 8;
			if (num[k] >= 5) num[k] += 2;
			else if (num[k] >= 4) ++num[k];
		} while (n /= 8);
		for (int i = k; i >= 0; --i) cout << num[i];
		cout << endl;
	}
	return 1;
}