#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;

  int num[8] = {0, 1, 2, 3, 5, 7, 8, 9};
  while (cin >> n, n) {
    vector<int> ans;
    while (n) {
      ans.push_back(n % 8);
      n /= 8;
    }

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i) {
      cout << num[ans[i]];
    }

    cout << endl;
  }
}