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

int main(){
	
	char ch[8] = {'0', '1', '2', '3', '5', '7', '8', '9'};
	int n;
	
	while( cin >> n, n ){
		string s;
		do{
			s.push_back( ch[n % 8] );
			n /= 8;
		}while( n > 0 );
		reverse( s.begin() , s.end() );
		cout << s << endl;
	}
}