#include<iostream>
using namespace std;
int ans[100];
int esc[8]={0,1,2,3,5,7,8,9};
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)break;
	int top=0;
	while(true){
		ans[top]=n%8;
		n/=8;
		if(n==0)break;
		top++;
	}
	for(int i=top;i>=0;i--)cout<<esc[ans[i]];
	cout<<endl;
	}
	return 0;
}