#include <iostream>
#include <vector>
#include <string>

using namespace std;

void reverse(vector<char>& vec){
	vector<char> tmp;
	for(int i = 0;i < vec.size();i++){
		tmp.push_back(vec[vec.size() - 1 - i]);
	}
	vec.clear();
	vec = tmp;
}


int main(void){
	int n;
	vector<char> ans;
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		while(n != 0){
			ans.push_back((char)('0' + (n % 8)));
			n /= 8;
		}
		reverse(ans);
		for(int i = 0;i < ans.size();i++){
			if('4' <= ans[i]){
				ans[i]++;
			}
			if('6' <= ans[i]){
				ans[i]++;
			}
		}
		for(int i = 0;i < ans.size();i++){
			cout << ans[i];
		}
		cout << endl;
		ans.clear();
	}


	return 0;
}