#include <iostream>
#include <string>
#define int long long
using namespace std;
signed main() {
	int a[10];
	a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 5; a[5] = 7; a[6] = 8; a[7] = 9;
	int n;
	while (cin >> n, n) {
		string ans;
		int m = n;
		while (m > 0) {
			ans = (char)(a[m % 8] + '0') + ans;
			m /= 8;
		}
		cout << ans << endl;
	}
}
