#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
	for(;;){
		int n;
		vector<int>a;
		scanf("%d",&n);
		if(n==0)return 0;

		while(n!=0){
			a.push_back(n%8);
			n/=8;
		}

		for(int i=a.size()-1;i>=0;i--){
			if(a[i]<=3)printf("%d",a[i]);
			if(a[i]==4)printf("%d",a[i]+1);
			if(a[i]>=5)printf("%d",a[i]+2);
		}
		printf("\n");
	}
}