#include <stdio.h>
  int main(){
/*(^(^(^(^(^o^)^)^)^)^) &#9602;&#9605;&#9607;&#9608;&#9619;&#9618;&#9617;('ω')&#9617;&#9618;&#9619;&#9608;&#9607;&#9605;&#9602; */
	  int m;
	  while(scanf("%d",&m)){
		  if(m==0) break;
		  int n[100],b=0,i;
		  while(m>=8){
			  n[b]=m%8;
			  m /= 8;
		      b++;
		  }
		  n[b]=m;
		  for(i=0;i<=b;i++){
			  if(n[i]==4){
				  n[i]=5;
			      continue;
			  }
			  if(n[i]==5){
				  n[i]=7;
			      continue;
			  }if(n[i]==6){
				  n[i]=8;
			      continue;
			  }
			  if(n[i]==7){
				  n[i]=9;
			      continue;
			  }}
		  for(i=b;i>=0;i--){
			  printf("%d",n[i]);
		  }
		  printf("\n");
	  }
		  return 0;
	  }