Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := []int{0, 1, 2, 3, 5, 7, 8, 9}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		out := make([]int, 10)
		now := 0
		for n > 0 {
			out[now] = table[n%8]
			now++
			n /= 8
		}
		tmp := make([]string, 0)
		for i := now - 1; i >= 0; i-- {
			tmp = append(tmp, strconv.Itoa(out[i]))
		}
		fmt.Println(strings.Join(tmp, ""))
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
	long long n;
	int num[8] = {0,1,2,3,5,7,8,9};
  while(true){
		cin>>n;
		if(!n)break;
		int newnum[20];
		for(int i=0;i<20;i++)
			newnum[i] = 0;

		int i=0;
		while(n>0){
			newnum[i] = n%8;
			n /= 8;
			i++;
		}

		long long ans = 0;
		for(i=19;i>=0;i--){
			ans *= 10;
			ans += num[newnum[i]];
		}
		cout<<ans<<endl;
	}
  return 0;
}

C++: #include<iostream>
int main(){
	int a;
	std::cin>>a;
	int g=0;
	for(int i=0;i<a;i++){
		g++;
		int n=10;
		for(int i=1;i<10;i++){
			if(g%n==4||g%n==6||g/n==4||g/n==6)g++;
			n*=10;
		}
	}
	std::cout<<g<<std::endl;
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int main(){
  int n,i,c,r[11];
  int ei[8]={1,2,3,5,7,8,9,0};
  while(1){
    cin>>n;
    if(n==0)break;
    
    for(i=0;n>=8;i++){      
      r[i]=n%8;
      n/=8;
    }
    r[i]=n;
    for(;i>=0;i--){
      cout<<ei[r[i]-1];
    }
    cout<<endl; 
  }
  return 0;
}

C++: #include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;


/** Problem0208 : Room Numbers of a Hospital **/
int main()
{
	string list="01235789";
	int n;
	while (cin >> n, n) {
		string ans;
		while (1) {
			ans+=(n%8)+'0';
			n/=8;
			if (n == 0) break;
		}
		reverse(ans.begin(), ans.end());
		rep(i, ans.length()) {
			cout << list[ans[i]-'0'];
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std ;

int N ;
int table[] = {0,1,2,3,5,7,8,9} ;

void Solve( int x ){
	if( x >= 8 ) Solve( x/8 ) ;
	cout << table[ x%8 ] ;
}

int main(){
	
	while( cin >> N , N ){
		Solve( N ) ;
		cout << endl ;
	}
	
	return 0 ;
}

C++: #include <iostream>
#include <cstdlib>

using namespace std;

int main(void)
{
	// itoa
	int n;
	while (cin >> n, n){
		char s[20];
		sprintf(s, "%o", n);
		
		string str = s;
		for (int i = 0; i < str.length(); i++){
			if ('4' <= str[i]) str[i]++;
			if ('6' <= str[i]) str[i]++;
		}
		cout << str << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

long long a[11]={0, 797380500, 1392951000, 2190321500, 2987902000, 3783282500, 5380853000, 7178223500, 7973805000, 8771185500, 9358757000};
char b[100000]={};

long long int number(int n){
  long long int h=0;
  int p=0;

  //if(n>=100000000 && n<200000000){p=100000000;h=a[1]}
  p=(n/100000000)*100000000;
  h=a[p/100000000];

  while(p<n){
    h++;
    if(b[h%100000]==1 && b[h/100000]==1)
      p++;
    }

  return h;
}
  


int main() {
    ios::sync_with_stdio(false);
    int s;
    int m=0;
    while(m<=99999){
      int t=m;
      while(t>0){
	if(t%10==4 || t%10==6)
	  {b[m]--;break;}
	else{
	  t=t/10;      
	}
      }
      b[m]++;
      m++;
    }
    
    int p,q;
    
    while (1) {
      cin >> s;
      if(s != 0){
	cout << number(s) << endl;
      }
      else
	break;
    }

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

string convi(string s) {
	char a[] = { '0','1','2','3','5','7','8','9' };
	string ret;
	for (auto c : s) {
		ret += a[c - '0'];
	}
	return ret;
}

int main() {
	int n;
	while (cin >> n && n) {
		stringstream ss;
		ss << oct << n;
		string s = ss.str();
		s = convi(s);
		Cout(s);
	}
}

C++: #include <iostream>
using namespace std;

unsigned long int dec_to_oct(unsigned long int num)
{
  int result = 0;
  for (int i = 1; num != 0; i *= 10)
  {
    result += (num % 8) * i;
    num = num / 8;
  }
  return result;
}

int main(void)
{
  unsigned long int room_num;
  unsigned long int buf;
  unsigned long int new_room_num;
  int num_table[8] = { 0, 1, 2, 3, 5, 7, 8, 9, };
  
  while (true)
  {
    cin >> room_num;
    if ( room_num == 0 ) break;
    buf = dec_to_oct(room_num);

    new_room_num = 0;
    for (int i = 1; buf != 0; i *= 10)
    {
      new_room_num += num_table[(buf % 10)] * i;
      buf /= 10;
    }

    cout << new_room_num << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int d[8]={0,1,2,3,5,7,8,9};
	int n;
	while(cin>>n,n){
		string out="";
		while(n){
			out=(char)(d[n%8]+'0')+out;
			n/=8;
		}
		cout<<out<<endl;
	}
}

C++: #inmport<cstdio>
s(int n){if(n>7)s(n/8);printf("%d",n%8<4?n%8:n%8<6?n%8+1:n%8+2);}main(){for(int a;scanf("%d",&a),a;puts(""))s(a);}

C++: while(1):
    n = int(input())
    if(not n):
        break
    print("".join("01235789"[int(i)] for i in oct(n)[2:]))

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main() {
    for(int N; cin >> N, N; ) {
        vector<int> vs;
        while(N >= 8) {
            vs.push_back(N % 8);
            N /= 8;
        }
        if(N != 0) vs.push_back(N);
        reverse(vs.begin(), vs.end());

        for(int c : vs) {
            if(c >= 4) c++;
            if(c >= 6) c++;
            cout << c;
        }
        cout << endl;
    }
}

C++: /*#include <iostream>

unsigned long long int func(unsigned long long int a);

unsigned long long answ[1000000000];

int main(){
	unsigned long long int n;
	while(std::cin >> n, n){
		unsigned long long int ans = 0;
		unsigned long long int n_=n;
		while(n_--){
			ans++;
			unsigned long long int b = func(ans); 
			ans+=b;
			n-=b;
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

unsigned long long int func(unsigned long long int a){
	int res=1;
	while(a > 0){
		if(a % 10 == 4 || a % 10 == 6)return res;
		a /= 10;
		res*=10;
	}
	return 0;
}*/

#include <iostream>
#include <stack>
#define  _m_ 1

const int Ebit[8]={0,1,2,3,5,7,8,9};

int main(){
	int n;
	std::stack<int> st;
	while(_m_){
		std::cin >> n;
		if(n==0)break;
		while(_m_){
			if(n<8){
				st.push(Ebit[n]);
				break;
			}
			int amari = n%8;
			n/=8;
			st.push(Ebit[amari]);
		}
		while(st.size()){
			std::cout<<st.top();
			st.pop();
		}
		std::cout<<std::endl;
	}
	return 0;
}