#include <iostream>

using namespace std;

int data[]={0, 1, 2, 3, 5, 7, 8, 9};
void solve(int);
main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    solve(n);
    cout << endl;
  }
  return 0;
}

void solve(int n){
  if(n>=8){
    solve(n/8);
  }
  printf("%d", data[n%8]);
}