#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main()
{
vector<string> v(8);
string s;
int n,i;
 
for(i=0;i<8;i++) v[i] = '0'+i+(i>=4)+(i>=5);
 
while(cin>>n,n){
 s = "";
 while(n>0){
  s += v[n%8];
  n /= 8;
 }
 reverse(s.begin(),s.end());
 cout<<s<<endl;
}
 
return 0;
}