#include<iostream>
using namespace std;

void solve(int n);

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		solve(n);
		cout << endl;
	}
}


void solve(int n){
	if(n == 0) return;
	solve(n/8);
	int a = n % 8;
	cout << (a==4?5:(a>4?a+2:a));
}