#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int conv[] = {0, 1, 2, 3, 5, 7, 8, 9};
int main () {
	ll n;
	while (cin >> n, n) {
		vector<int> oct;
		while (n >= 8) {
			oct.push_back(n % 8);
			n /= 8;
		}
		oct.push_back(n);
		for (vector<int>::reverse_iterator it = oct.rbegin(); it != oct.rend(); ++it) {
			cout << conv[*it];
		}
		cout << endl;
	}
	return 0;
}