// Probable......

import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	
	public static void main(String[] args) {
		int[] a = {0, 0, 0, 0, 3, 0, 5, 0, 7, 7, 7, 0, 11, 0, 13, 7, 7, 0, 8, 0, 19, 19, 7, 0, 23, 23};
		Scanner sc = new Scanner(System.in);
		BigInteger n = sc.nextBigInteger();
		int v;
		if( n.compareTo(new BigInteger("26")) < 0 ) {
			v = a[ (int) n.longValue() ];
		} else {
				if(
						n.mod(new BigInteger("8")).compareTo(BigInteger.ONE) == 0 &&
						n.subtract(new BigInteger("8")).isProbablePrime(80)
				)
				{
					v = 14;
				} else {
					v = 8;
				}
		}
		System.out.println(v);
	}
	
}