#include <cstdio>
#include <stdlib.h>
#include <cstring>


using namespace std;

int main(void){
	int i, n;
	char ans[128];
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		sprintf(ans,"%o",n);
		for(i = 0;i < strlen(ans);i++){
			if(ans[i] >= '5'){
				ans[i] += 2;
			}else if(ans[i] == '4'){
				ans[i]++;
			}
		}
		printf("%s\n",ans);
	}
	return 0;
}