#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
	unsigned n;
	while (cin >> n, n) {
		int b=1;
		long long m=0;
		while (n) {
			m += b*(n%8);
			n /= 8;
			b *= 10;
		}

		stringstream ss;
		string s;
		ss << m;
		ss >> s;
		ss.str("");
		ss.clear(stringstream::goodbit);
		for (int i=0; i<s.size(); i++) {
			if (s[i]=='4') s[i]='5';
			else if (s[i]=='5') s[i]='7';
			else if (s[i]=='6') s[i]='8';
			else if (s[i]=='7') s[i]='9';
		}
		ss << s;
		ss >> m;
		cout << m << endl;
	}
	return 0;
}