#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int main(){
	int N;
	while(cin >> N, N)
	{
		string ans;
		int w = 1;
		while(w < 1e9) w *= 8;
		while(w > 0)
		{
			ans.push_back('0' + N / w);
			N %= w;
			w /= 8;
		}
		bool flag = true;
		for(int i = 0; i < ans.size(); i++)
		{
			char out = ans[i];
			if(flag && out == '0') continue;
			flag = false;
			if(out >= '4') out++;
			if(out >= '6') out++;
			printf("%c", out);
		}puts("");
	}
	return 0;
}