#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int ex[] = {0, 1, 2, 3, 5, 7, 8, 9};

string f(ll n)
{
	string a;
	while(n)
	{
		if(n <= 8)
		{
			a += ex[n] + '0';
			break;
		}
		a += ex[n % 8] + '0';
		n /= 8;
	}
	reverse(a.begin(), a.end());

	return a;
}

int main()
{
	ll n;
	while(cin >> n, n)
	{
		cout << f(n) << endl;
	}
}