#include <iostream>
#include <math.h>

using namespace std;

int main(){
  char newnum[8] = {0,1,2,3,5,7,8,9};
  long input_num,output_num;
  int count_num;
  while(cin >> input_num && input_num != 0){
    output_num = 0;
    count_num = 0;
    while(input_num != 0){
      output_num += newnum[input_num % 8] * pow(10,(double)count_num);
      input_num /= 8;
      //      cout << output_num << " " ;
      count_num++;
    }
    cout << output_num;
    cout << endl;
  }

}