import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(read()) def MillerRabinTest(n, maxiter = 10): import random if n == 1: return False elif n == 2: return True if not n&1: return False d = n - 1 while not (d & 1): d >>= 1 for _ in range(maxiter): a = random.randint(1,n-1) t = d x = pow(a,t,n) while (t != n-1) and (x != 1) and (x != n - 1): x = x * x % n t <<= 1 if (x != n-1) and not (t & 1): return False return True def F(N): A = [ 0,0,0,0,3,0,5,0,7,7, # 0 ~ 9 7,0,11,0,13,7,7,0,8,0, # ~19 19,19,7,0,23,23,8,8,8 ] if N < 30: return A[N] for x in [8,14]: if N % x != 1: return x if not MillerRabinTest(N - x): return x raise Exception # ないはず answer = F(N) print(answer)