#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
char m[] = {'0','1','2','3','5','7','8','9'};
signed main(){
	int a;
	while( scanf("%lld", &a) != EOF ){
		if (a==0) break;
		vector<int> x(0,0);
		int l = 0;
		while(a>0){
			x.push_back(a%8);
			a/=8;
			l++;
		}
		for(unsigned int i=0;i<l;i++){
			cout << m[x[l-i-1]];
		}
		cout << endl;
	}
	return 0;
}