from random import randint
n = input()
m = {3: [4], 5: [6], 7: [8,9,10,15,16,22], 11: [12], 13: [14], 19: [20,21], 23: [24,25]}

def miller_rabin(n):
    if n==2: return 1
    if n==1 or n&1==0: return 0
    d = n-1
    d /= d & -d
    for k in xrange(1000):
        a = randint(1, n-1)
        t = d
        y = pow(a, t, n)
        while t!=n-1 and y!=1 and y!=n-1:
            y = y**2 % n
            t <<= 1
        if y!=n-1 and t&1==0: return 0
    return 1

for w in m:
    if n in m[w]:
        print w
        break
else:
    if (n%8!=1 and not miller_rabin(n-1)) or not miller_rabin(n-8):
        print 8
    else:
        print 14