#include<iostream>
using namespace std;

 const int table[] = { 1,2,3,4,5,6,7,8,9 };
 void surgeon(int x)
 {
  if(x>=8)
  {
  surgeon(x/8);
  }
 return(table[x%8]);
 }
 int main()
 {
 int x;
 while(cin>>x, x>0)
 {
  surgeon(n);
  cout<<endl;
  }
 return 0;
}