#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>


#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

#define PII pair<int,int>
#define PP pair< int,PII >


using namespace std;

int main(){
	
	int n;
	char x[128];
	char deco[] ={"5789"};
	int l;
	while(scanf("%d", &n),n){
		sprintf(x, "%o", n);
		l = strlen(x);
		rep(i,l){
			rep(j,4){
				if(x[i] == '4'+j){
					x[i] = deco[j];
					break;
				}
			}
		}
		puts(x);
	}
	return 0;
}