#include<iostream>
#include<string>
#include<algorithm>
#include<bitset>
typedef unsigned long ulong;

using namespace std;

string Oct(ulong n){
	string s;
	bitset<32> b(n);

	while( b.any() ){
		int c = (b[2]?1:0) * 4 + (b[1]?1:0) * 2 + (b[0]?1:0);
		s += (c + '0');
		b >>= 3;
	}
	reverse( s.begin(), s.end() );
	return s;
}
int main(){
	while(true){
		string sNum;
		ulong n;

		cin >> n;
		
		if( n == 0 )
			break;

		sNum = Oct(n);

		for(unsigned int i = 0; i < sNum.length(); ++i){
			switch( sNum[i] ){
				case '4':
					sNum[i] = '5';
					break;
				case '5':
				case '6':
				case '7':
					sNum[i] += 2;
					break;
			}
		}

		cout << sNum << '\n';
	}
	return 0;
}