#include <iostream>
#include <algorithm>
//#include <fstream>

using namespace std;

string dec2oct (int n )
{
	string res = "";

	while (n > 0 ){
		res += n % 8 + '0';
		n /= 8;
	} // end while
	
	reverse (res.begin(), res.end() );

	return res;
}

string hostpial_number (string s )
{
	int len = s.length();
	string res = "";
	int i;

	for (i = 0; i < len; ++i){
		if (s[i] != '4' && s[i] != '5' && s[i] != '6' && s[i] != '7'){
			res += s[i];
		}else if (s[i] == '4'){
			res += '5';
		}else if (s[i] == '5'){
			res += '7';
		}else if (s[i] == '6'){
			res += '8';
		}else if (s[i] == '7'){
			res += '9';
		} // end if
	} // end for

	return res;
}


int main()
{
//	cut here before submit 
//	freopen ("testcase.hospitalnumber", "r", stdin );
	int n;

	while (cin >> n && n ){
		string oct = dec2oct (n );
		string res = hostpial_number (oct );
		cout << res << endl;
	} // end loop
		
	return 0;
}