#include<iostream>
using namespace std;

int main(){
  int i,j;
  int n;
  int a[10];

  while(1){
    cin >> n;
    if(!n)break;

    j = 0;
    while(1){
      a[j] = n%8;
      n /= 8;
      if(!n)break;
      j++;
    }

    for(i=j;i>=0;i--){
      if(a[i]<4)cout << a[i];
      else if(a[i]<5)cout << a[i]+1;
      else cout << a[i]+2;
    }
    cout << endl;
  }
}