#include <iostream>
using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208

int d[] = { 0, 1, 2, 3, 5, 7, 8, 9 };

int div(int n) {
	if (n >= 8) div(n / 8);
	cout << d[n % 8];
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		div(n);
		cout << endl;
	}
	return 0;
}