#include<iostream>

int n;
int pw[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

void solve(){
	unsigned long long ans = 0;
	int tmp = n;
	for(int i=0; i<10; i++){
		int temp = tmp%8;
		if(temp==4)
			temp++;
		else if(temp > 4)
			temp+=2;
		ans += temp*pw[i];
		tmp = tmp/8;
		if(tmp == 0)
			break;
	}
	std::cout << ans << std::endl;
}

int main(){
	while(true){
		std::cin >> n;
		if(!n)
			return 0;
		solve();
	}
}