#include<iostream>
#include<vector>

using namespace std;

int TableNewOctal[] = { 0,1,2,3,5,7,8,9 };
vector<int> Result;

int main() {
	int num;

	while (cin >> num, num) {
		while (num > 0) {
			Result.push_back(TableNewOctal[num % 8]);
			num /= 8;
		}
		while (!Result.empty()) {
			cout << Result.back();
			Result.pop_back();
		}
		cout << endl;
	}

	return 0;
}
