#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main( void )
{
	long long n;
	while ( cin >> n && n != 0 )
	{
		ostringstream os;
		os << oct << n;
		string n_str = os.str();
		for ( string::iterator it = n_str.begin(); it != n_str.end(); it++ )
		{
			char c = *it;
			if ( c >= '4' ) (*it)++;
			if ( c >= '5' ) (*it)++;
		}
		istringstream is( n_str );
		is >> n;
		cout << n << endl;
	}

	return 0;
}