#include<iostream>
#define len 12

using namespace std;

char num[12];
int in;

int main () {

  while ( true ) {
    cin >> in;

    if ( in == 0 )
      break;

    for ( int i=11; i>=0; i-- ) {
      num[i] = (in & 7) + '0';
      //num[i] = in%8+'0';
      in = in>>3;
    }
  
    int count = 0;
    while ( num[count] == '0' )
      count++;
  

    for ( int i=count;i <len; i++ ) {
      if ( num[i] == '4' )
	cout << '5';
      else if ( num[i] >'4' )
	cout << (char)(num[i]+2);
      else
	cout << num[i];
    }
    cout << endl;
  }

}