#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
char h[]="01235789";
main(){
  while(1){
    ll n;
    scanf("%lld",&n);
    if(!n) break;
    ll a=0;
    ll k=1;
    while(n>0){
      a += (k*(n%8));
      k*=10;
      n/=8;
    }
    char r[15]={};
    int i=0;
    while(a>0){
      r[i]=a%10;
      a/=10;
      ++i;
    }
    for(int j=i-1;j>-1;j--) printf("%c",h[r[j]]);
    puts("");
  }
}