#include<iostream>
#include<stack>
using namespace std;

int main(){
  int no, i;
  stack<int> sum;
  while(cin >> no, no) {
    for( i = 1;no > 8; i*=10){
      sum.push(no % 8);
      no /= 8;

    }
    sum.push(no);
    while(sum.size()) {
      no = sum.top();
      if(no % 8 == 4) no++;
      else if(no % 8 >= 5) no+=2;
      cout << no;
      sum.pop();
    }
    cout << endl;
  }
  return 0;
}