#include <stdio.h>

#define N 8
int main(void){
    long int n,q, dig;
    int num[]={0,1,2,3,5,7,8,9};
     
    while (scanf("%d", &n), n!=0){
        dig = 0;        
        q=0;
        while (n){
            q += n%N;
            q *= 10;
            n /= N;
            dig++;
        }
        q /= 10;
        if (dig){
            while (dig--){
                printf("%d", num[q%10]);
                q /= 10;
            }
        } else printf("0");
        printf("\n");
    }
     
    return 0;
}