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

int main()
{
	int n;
	while(cin >> n){
		if(!n){
			break;
		}
		int bit[100];
		int a=0;
		while(n!=0){
			bit[a++] = n%8;
			if(bit[a-1] >= 4)
				bit[a-1]++;
			if(bit[a-1] >=6)
				bit[a-1]++;
			n/=8;
		}
		for(int i=a-1;i>=0;i--)
			cout << bit[i];
		cout << endl;
	}
	return 0;
}