import java.math.*; import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] num = new int[n]; for(int i=0;i sosuu = new ArrayList<>(); sosuu.add(0); boolean[] sosu=new boolean[5000001]; for(int i=2;i<=5000000;i++){ if(!sosu[i]){ sosuu.add(i); for(int j=i*2;j<=5000000;j+=i){ sosu[j]=true; } } } sosuu.add(5000001); int target=0; for(int i=0;i0){ temp1 |=(1<<(temp%10)); temp/=10; } cur |= temp1; hi=i; if(target==cur){ ans=Math.max(ans, sosuu.get(hi+1)-sosuu.get(rou-1)-2); }else if((target|cur)-target>0){ rou=hi=i+1; cur=0; } } System.out.println(ans); } }