#include<stdio.h>
int main(){
int i,n,count=0,s,a;
scanf("%d",&n);
for(i=1;i<=1000000000;i++){
s=i;
while(s){
a=s%10;
if(a!=4&&a!=7) break;
if(1<=s&&s<=10) {
count++;}
s=s/10;
}
if(count==n) break;
}
printf("%d\n",i);
return 0;
}