#include <iostream>
#include <vector>
using namespace std;
int n[] = { 0,1,2,3,5,7,8,9 };

int main() {
	while(true){
	vector<int>v;
	long long num;
	cin >> num;
	if (num == 0) return 0;
	while (num >= 1) {
		v.push_back(n[num % 8]);
		num /= 8;
	}
	for (int i = v.size() - 1; i >= 0; i--) cout << v[i];
	cout << endl;
}
}

