#include <iostream>
#define int long long
using namespace std;

signed main(){
	int chg[] = {0,1,2,3,5,7,8,9};
	int n;
	while(cin >> n,n){
		int nn = n,to = 0,tmp = 1,keta = 0;
		while(nn){
			to += (nn % 8) * tmp;
			tmp *= 10;
			nn /= 8;
			keta++;
		}
		tmp = 1;
		for(int i = 0;i < keta;i++){
			int pos = (to / tmp) % 10;
			to += (chg[pos] - pos) * tmp;
			tmp *= 10;
		}
		cout << to << endl;
	}
	return 0;
}