package no006; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int k = sc.nextInt(); int n = sc.nextInt(); ArrayList primes = Sieve.primeList(n); int ans = 0; int max = 0; int i = 0; while(i < primes.size() && primes.get(i) < k) { i++; } for(;i<=n;i++) { boolean[] used = new boolean[10]; for(int j=i;j= max) { max = j - i + 1; ans = primes.get(i); } } } System.out.println(ans); } static int uselessHash(int n) { while(n >= 10) { int sum = 0; while(n > 0) { sum += n % 10; n /= 10; } n = sum; } return n; } } class Sieve { public static boolean[] isPrimeArray(int max) { boolean[] isPrime = new boolean[max+1]; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for(int i=2;i*i<=max;i++) { if (isPrime[i]) { int j = i * 2; while(j<=max) { isPrime[j] = false; j += i; } } } return isPrime; } public static ArrayList primeList(int max) { boolean[] isPrime = isPrimeArray(max); ArrayList primeList = new ArrayList<>(); for(int i=2;i<=max;i++) { if (isPrime[i]) { primeList.add(i); } } return primeList; } }