#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(){
  int n;
  char room[11];

  while(cin >> n, n){
    //printf("%o\n", n);
    sprintf(room, "%o", n);
    for(int i = 0 ; i <= 10 ; i++){
      if(room[i] < '4') continue;
      else if(room[i] == '4') room[i] = '5';
      else if(room[i] > '4') room[i] += 2;
    }
    cout << room << endl;
  }
  return 0;
}