#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	while(1)
	{
		vector<int> vec;
		int n;
		cin >> n;
		if(n==0)break;
		while(1)
		{
			vec.pb(n%8);
			if(n<8)break;
			n/=8;
		}
		reverse(vec.begin(),vec.end());
		for(int i=0;i<vec.size();i++)
		{
			if(vec[i]==4)
			{
				vec[i]++;
			}
			else if(vec[i]==5||vec[i]==6||vec[i]==7)
			{
				vec[i]+=2;
			}
		}
		for(int i=0;i<vec.size();i++)
		{
			cout << vec[i];
		}
		cout << endl;
	}
	return 0;
}