#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){

	int n;
	int tmp;
	string s;

	while(1){

		cin>>n;
		if(n==0) break;

		s="";
		
		while(n!=0){
			tmp=n%8;
			if(tmp>=4) tmp++;
			if(tmp>=6) tmp++;
			s+=tmp+'0';
			n/=8;
		}

		for(int i=0;i<s.size()/2;i++){
			swap(s[i],s[s.size()-i-1]);
		}

		cout<<s<<endl;
	}
}