#include<iostream>
#include<cstdio>

using namespace std;

int main(){
  int n;
  int i,c,r[11];
  int ei[8]={0,1,2,3,5,7,8,9};
  while(1){
    cin>>n;
    if(n==0)break;
    
    for(i=0;n>=8;i++){      
      r[i]=n%8;
      n/=8;
    }
    r[i]=n;
    for(;i>=0;i--){
      cout<<ei[r[i]];
    }
    cout<<endl; 
  }
  return 0;
}