#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    while(1)
    {
        long long n;
        cin>>n;if(!n)return 0;
        long long a=n;
        int k=-1;
        for(;a>0;++k){
            a/=8;
        }
        for(;k>=0;--k){
            int ans=n/pow(8,k);
            if(ans==4)cout<<5;
            else if(ans>4)cout<<ans+2;
            else cout<<ans;
            n=n%(long long)pow(8,k);
        }
        cout<<endl;
    }
    return 0;
}