#include<iostream>
using namespace std;
int main(){
long n,d[10],i,j,a,b[8]={0,1,2,3,5,7,8,9};
while(cin>>n){
if(n==0)break;
for(i=0;;i++){
a=n/8;
d[i]=n%8;
n=a;
if(n==0)break;
}
for(j=i;j>=0;j--)cout<<b[d[j]];cout<<endl;
}
return 0;
}