#include<stdio.h>
int main(void){
   int n, r, w, N;
   scanf("%d", &n);
   while(n){
       if ( n % 8 >= 5 ) N = n / 8 * 10 + n % 8 + 2;
       else if ( n % 8 >= 4 )  N = n / 8 * 10 + n % 8 + 1;
       else N = n / 8 * 10 + n % 8;
       printf("  %d\n", N);
       scanf("%d", &n);
    }
    return 0;
}