#include <iostream>
#include <cmath>
using namespace std;
int main(){

  long long int n,result,n8,blank,i;

  while(cin>>n,n){
    
    result=0;
    for(i=20;i!=-1;i--){
      
      n8=pow(8,i);
      blank=n/n8;
      if(blank>=4) blank++;
      if(blank>=6) blank++;
      result+=blank*pow(10,i);
      n=n%n8;
      
    }
    
    cout<<result<<endl;

  }
  
  return 0;

}
      
    
    