#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(void){
  int n,t,c;
  long double a[15];
  a[10] = pow(8.0,10.0);
  a[9]  = pow(8.0,9.0);
  a[8]  = pow(8.0,8.0);
  a[7]  = pow(8.0,7.0);
  a[6]  = pow(8.0,6.0);
  a[5]  = pow(8.0,5.0);
  a[4]  = pow(8.0,4.0);
  a[3]  = pow(8.0,3.0);
  a[2]  = pow(8.0,2.0);
  a[1]  = pow(8.0,1.0);
  a[0]  = pow(8.0,0);
  while(cin >> n,n){
    string ans;
    for(int i = 10;i >= 0; i--){
      if((int)a[i] <= n){
	t = i;
	break;
      }
    }
    for(int i = t;i >= 0; i--){
      c = n / (int)a[i];
      n -= c * (int)a[i];
      if(c == 0) ans += "0";
      else if(c == 1) ans += "1";
      else if(c == 2) ans += "2";
      else if(c == 3) ans += "3";
      else if(c == 4) ans += "5";
      else if(c == 5) ans += "7";
      else if(c == 6) ans += "8";
      else if(c == 7) ans += "9";
      else ans += "F";
    }
    cout << ans << endl;
  }
}
