#include<iostream>
#include<string>

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

int main(){
	int n;
	while (std::cin >> n, n){
		std::string v;

		while (n != 0){
			char a;
			a = n % 8 + '0';
			v += a;
			n /= 8;
		}
		for (int i = v.size() - 1; i >= 0; i--){
			int j = v[i] - '0';
			v[i] = q[j] + '0';
			std::cout << v[i];
		}
		std::cout << std::endl;
	}
	return 0;
}