#include <iostream>
using namespace std; 

int main(){  
	while(true){     
		int n;
		int i=0;
		int x[256],y;
		cin >> n;
		if(n==0)         
			break;   

		while(true){
			x[i] = n;
			i++;
			n = n/8;
			if(n==0)
				break;
			
		}
		for(int j=i; j>0; j--){
			y = x[j-1] % 8;
			
			if(y < 4)
				cout << y;
			else if(y == 4)
				cout << y+1;
			else if(y > 4)
				cout << y+2;
		}
		cout << endl;
	}
	return 0;
}