#include <iostream>
#include <cmath>
#include <string>
using namespace std;
const int INF=2<<20;
typedef long long int llf;
int main() {
	// your code goes here
	int num[8]={0,1,2,3,5,7,8,9};
	llf x=50,y,tx,ty,kx,ky,ans;
	llf n;
	while(cin >> n && n!=0){
		x=50;
		while(n/(llf)pow((llf)8,(llf)x)==0)
		x--;
		while(x!=-1){
			cout << num[(n%((llf)pow((llf)8,(llf)x+1)))/(llf)pow((llf)8,(llf)x)];
			x--;
		}
		cout << endl;
		
	}
	return 0;
}