import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Main p = new Main(); } public Main() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i primeList = new ArrayList(); primeList.add(0); for(int i=2;i0){ curShift |= (1<<(curNum%10)); curNum/=10; } cur |= curShift; high = i; if(target == cur){ res = Math.max(res, primeList.get(high+1)-primeList.get(low-1)-2); }else if((target|cur)-target > 0){ low = high = i+1; cur = 0; } } if(res==0) System.out.println(-1); else System.out.println(res); } }