#include <iostream>
#include <vector>
#include <algorithm>

std::vector<int> ToOctalNumber(int n){
	std::vector<int> res;
	while(n){
		res.push_back((n&7)<4?n&7:(n&7)==4?5:(n&7)+2);
		n >>= 3;
	}
	std::reverse(res.begin(), res.end());
	return res;
}

int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> sample = ToOctalNumber(n);
		for(int i=0;i<sample.size();i++){
			std::cout << sample[i];
		}
		std::cout << "\n";
	}
}