#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
void solve(int);
int main(){
  int n;
  while(cin >> n && n){
    solve(n);
    cout << endl;
  }
}
void solve(int n){
  if(n == 0) return;
  solve(n/8);
  int a=n%8;
  cout << (a==4?5:(a>4?a+2:a));
}