#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int NUM = 1000000000;
const int L = 11;

string translation(int N){
  stringstream ss;
  while(N > 0){
    ss <<N % 8;
    N /= 8;
  }
  string s = ss.str();
  REVERSE(s);
  return s;
}

int main() {
  char n[9] = {'0', '1', '2', '3', '5', '7', '8', '9'};
  int N;
  while(cin >>N && N){
    string s = translation(N);
    REP(i, s.length()) cout <<n[s[i] - '0'];
    cout <<endl;
  }
  return 0;
}