#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int judge(char[], char[], char[], int);

int main() {

	int i, n, count;
	char s1[64];
	char s2[2]="4";
	char s3[2]="6";

	while(cin >> n) {
		count=0;
		if(n==0)
			break;
		for(i=1; i<=n; i++) {
			count++;
			count=judge(s1, s2, s3, count);
		}
		cout << count << endl;
	}

	return 0;

}

int judge(char s1[], char s2[], char s3[], int count) {

	sprintf(s1, "%d", count);
	while((strpbrk(s1, s2)!=NULL)||(strpbrk(s1, s3)!=NULL)) {
		count++;
		sprintf(s1, "%d", count);
	}

	return count;

}