#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){
	int n;

	stack<int> S;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		while(n > 0){
			S.push(n%8);
			n /= 8;
		}

		while(!S.empty()){
			switch(S.top()){
			case 0:
				printf("0");
				break;
			case 1:
				printf("1");
				break;
			case 2:
				printf("2");
				break;
			case 3:
				printf("3");
				break;
			case 4:
				printf("5");
				break;
			case 5:
				printf("7");
				break;
			case 6:
				printf("8");
				break;
			case 7:
				printf("9");
				break;
			}
			S.pop();
		}
		printf("\n");
	}

    return 0;
}