https://www.acmicpc.net/problem/1526
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
String n=s.next();
while(true){
int c = 0;
for(int i=0;i<n.length();i++){
if(n.charAt(i)!='4' && n.charAt(i)!='7'){
c=1;
break;
}
}
if(c==0) break;
else n=String.valueOf(Integer.parseInt(n)-1);
}
System.out.print(n);
}
}