#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	while(cin >> n,n){
		deque<int> va;
		while(n){
			va.push_front(n%8);
			n=n/8;
		}
		for(int i=0;i<va.size();i++){
			if(va[i]==4)va[i]++;
			else if(va[i]==5)va[i]+=2;
			else if(va[i]==6)va[i]+=2;
			else if(va[i]==7)va[i]+=2;
			cout << va[i];
		}
		cout << endl;
	}
	return 0;
}