//#include <iostream>
//#include <string>
#include <stdio.h>

//using namespace std;

/*long long a[21]={0, 298790200, 797380500, 1095170800, 1392951000, 1891731200, 2190321500, 2589111800, 2987902000, 3285592200, 3783282500, 5082072800, 5380853000, 5879533200, 7178223500, 7577013800, 7973805000, 8272395200, 8771185500, 9059975800, 9358757000};
char b[100000]={};

long long int number(int n){
  long long int h=0;
  int p=0;

  p=(n/50000000)*50000000;
  h=a[p/50000000];

  while(p<n){
    h++;
    if(b[h%100000]==1 && b[h/100000]==1)
      p++;
    }

  return h;
}


int main() {
    ios::sync_with_stdio(false);
    int s;
    int m=0;
    while(m<=99999){
      int t=m;
      while(t>0){
	if(t%10==4 || t%10==6)
	  {b[m]--;break;}
	else{
	  t=t/10;      
	}
      }
      b[m]++;
      m++;
    }
    
    int p,q;
    
    while (1) {
      cin >> s;
      if(s != 0){
	cout << number(s) << endl;
      }
      else
	break;
    }

    return 0;
}
*/

char str[15];

char* number(int n){
  sprintf(str, "%o", n);
  int i;
  for(i=0;i<15;i++){
    if(str[i]>='4')
      {str[i]++;}
    if(str[i]>='6')
      str[i]++;
  }
  
  return str;
}



int main(){
  int s;
  while (1) {
    scanf("%d", &s);
    if(s != 0){
      //cout << number(s) << endl;
      printf("%s\n", number(s));
    }
    else
      break;
  }
  
  return 0;
}