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 fermat(k): for t in xrange(1000): a = randint(2, k-1) if pow(a, k-1, k)!=1: return 0 return 1 for w in m: if n in m[w]: print w exit(0) if (n%8!=1 and not fermat(n-1)) or not fermat(n-8): print 8 else: print 14