#include<iostream>
#include<stack>
using namespace std;

int num(int x) {
	if (x == 4)return 5;
	else if (x > 4)return x + 2;
	else return x;
}

int main() {
	int n;
	while (cin >> n, n) {
		stack<int>st;
		while (n > 7) {
			int a = (n % 8);
			a = num(a);
			st.push(a);
			n /= 8;
		}
		st.push(n);

		int b = st.size();
		for (int i = 0;i < b;i++) {
			cout << st.top();
			st.pop();
		}
		cout << endl;
	}
	return 0;
}