#include <iostream>
#include <vector>

using namespace std;

int MAX_N = 1000000000;

void hex(vector<int> *c, int num);

int main(int argc, char** argv)
{
	int n, d;
	vector<int> v;
	while( 1 )
	{
		v.clear();
		cin >> n;
		if(n==0) break;

		hex(&v, n);
		for(int i=0; i<v.size(); i++){
			d = v[v.size() - i - 1];
			if(d>=4) d++;
			if(d>=6) d++;
			cout << d;
		}
		cout << endl;
	}
}

void hex(vector<int> *c, int num)
{
	int count = 0;
	while(num != 0)
	{
		c->push_back(num % 8);
		num /= 8;
	}
}