#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;



int main() {
  long long n;
  int hex[] = {0, 1, 2, 3, 5, 7, 8, 9};
  while (cin >> n, n) {
    string res = "";
    while (n) {
      stringstream ss;
      ss << hex[n%8];
      res = ss.str() + res;
      n /= 8;
    }
    cout << res << endl;
  }
}