import java.util.*; import java.util.stream.*; import static java.lang.Math.*; public class Main{ public static void main(String... args){ Scanner sc=new Scanner(System.in); boolean[] isPrime=new boolean[5000001]; Arrays.fill(isPrime,true); isPrime[0]=false; isPrime[1]=false; for(int i=2;i primes=new ArrayList<>(); for(int i=0;i set=new HashSet<>(); int j=i; while(j=primes.size()?5000000:primes.get(j)-1; //put("(l,r)=(%d,%d)",l,r); max=max(max,r-l); i=j; } put(max); } public static boolean canUse(int x,boolean[] canUses){ for(char c:Integer.toString(x).toCharArray()){ if(!canUses[c-'0'])return false; } return true; } public static class Pair{ final int x,y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public String toString(){ return String.format("Pair(%d,%d)",x,y); } } public static void print(Object object){ System.out.print(object); } public static void put(Object object) { System.out.println(object); } public static void put(){ System.out.println(); } public static void print(String format,Object... args){ System.out.print(String.format(format,args)); } public static void put(String format,Object... args) { System.out.println(String.format(format,args)); } }