#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

vector<long long int>memo(20);
long long int getans(const long long  int n) {
	if (n <= 3)return n;
	else if (n == 4)return 5;
	else if (n <= 9)return n + 2;
	else {
		int keta;
		for (int i = 19; i >= 0; --i) {
			if (memo[i] < n) {
				keta = i;
				break;
			}
		}
		int num = n / memo[keta];
		if (num <= 3) {
			return powint(10, keta)*num + getans(n - memo[keta] * num);
		}
		else if (num == 4) {
			return powint(10, keta)*(num+1) + getans(n  - memo[keta] * num);
		}
		else {
			return powint(10, keta)*(num+2) + getans(n - memo[keta] * num);
		}

	}
}

int main() {
	memo[1] = 8;
	for (int i = 2; i < 20; ++i) {
		memo[i] = memo[i - 1] * 8;
	}
	while (1) {
		int N; cin >> N;
		if (!N)break;
		else {
			long long int ans = getans(N);
			cout << ans << endl;
		}

	}
	return 0;
}