#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;


int fourOrSixPlace(ll num){
	int idx=-1;
	int cnt=0;
	while(num>0){
		if(num%10==6||num%10==4){
			idx=cnt;
		}
		num/=10;
		cnt++;
	}
	return idx;
}

int main(){

	//int cc=0;
	//for(ll i = 1; i <= 100000; i++){
	//	int ret=fourOrSixPlace(i);
	//	if(ret!=-1)
	//		cc++;
	//}
	//cout<<cc<<endl;
	ll n;
	while(cin>>n&&n!=0){
		ll cnum=0;
		ll cnt=0;
		while(1){
			if(cnum>10000000000LL){
				return 0;
			}
			cnum+=100000;
			if(cnum>n)
				break;
			int ret=fourOrSixPlace(cnum);
			if(ret==-1){
				n+=67232;
			}
			else{
				n+=67232;
				cnum+=(ll)pow(10.0,ret);
				n+=(ll)pow(10.0,ret);
			}
		}

		if(true){
			cnum-=100000;
			cnum++;
			for(ll i = cnum; i <= n; i++){
				int ret=fourOrSixPlace(i);
				if(ret!=-1){
					if(ret==0){
						n++;
					}
					else{
						n+=(ll)pow(10.0,ret);
						i+=(ll)pow(10.0,ret);
					}
				}
			}
		}
		cout<<n<<endl;
	}


	return 0;
}