import java.util.*; import java.math.*; class main { public static BigInteger trans(int x) { return BigInteger.valueOf(x); } public static void main(String[] args) { int []ans={-1,-1,-1,-1,3,-1,5,-1,7,7,7,-1,11,-1,13,7,7,-1,8,-1,19,19,7,-1,23,23}; Scanner sc = new Scanner(System.in); BigInteger n = sc.nextBigInteger(); if(n.compareTo( trans(25) )<=0) System.out.println(ans[n.intValue()]); else { if( n.mod(trans(8)).compareTo(trans(1))==1 && n.subtract(trans(8)).isProbablePrime(20) ) System.out.println(14); else System.out.println(8); } } }