#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(){
    int in_num;
    char num_s8[12];
    while(1){
        cin  >> in_num;
        if(in_num == 0){
            break;
        }
        snprintf(num_s8, sizeof(num_s8), "%o", in_num);
        for(int i=0; i<strlen(num_s8); i++){
            if(num_s8[i] == '4'){
                num_s8[i] = '5';
            }
            
            else if(num_s8[i] == '5'){
                num_s8[i] = '7';
            }
            
            else if(num_s8[i] == '6'){
                num_s8[i] = '8';
            }
            else if(num_s8[i] == '7'){
                num_s8[i] = '9';
            }
            
        }
        printf("%s\n", num_s8);
    }
   
    return 0;
}