#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int room;
    char hospital[11];
	
    while(cin >> room, room)
    {
        sprintf(hospital, "%o", room);
    	
    	for(int i = 0; i < 11; i++)
    	{
    		if(hospital[i] == '4')
    		{
    			hospital[i] = '5';
    		}
    		else if(hospital[i] > '4')
    		{
    			hospital[i] += 2;
    		}
    	}
    	cout << hospital << endl;
    }
    
    return 0;
}