#include <stdio.h>
#include <string.h>

int main(void)
{
	int old;
	int i, len;
	char ne[100];
	while (1){
		scanf("%d", &old);
		
		if (old == 0){
			break;
		}
		
		i = 0;
		while (old != 0){
			ne[i] = old % 8 + '0';
			old /= 8;
			i++;
		}
		ne[i] = '\0';
		len = strlen(ne) - 1;
	
		for (i = 0; i <= len; i++){
			if ('5' <= ne[len  - i]){
				ne[len - i] += 2;
			}
			else if ('4' <= ne[len - i]){
				ne[len - i]++;
			}
			
			printf("%c", ne[len - i]);
		}
		puts("");
	}
	return (0);
}