#include <iostream>
#include <string>

using namespace std;

int main() {
	long long int n;
	string kazu = "01235789";
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string b = "";
		while (n != 0) {
			b += kazu[n%8];
			n /= 8;
		}
		for (int i = b.size()-1; i >= 0; i--) {
			cout << b[i];
		}
		cout << endl;
	}
	return 0;
}