import random import queue def is_prime(n): if n==1: return False if n==2: return True if n%2==0: return False q = (n-1)>>1 while q&1 == 0: q >>= 1 # print("n={}, q={}".format(n, q)) for i in range(30): a = random.randint(1, n-1) a_pow = pow(a, q, n) if a_pow == 1: continue j = 0 while a_pow != n-1 and (1<<(j+1))*q != n-1: a_pow *= a_pow a_pow %= n j+=1 if (1<<(j+1))*q==n-1 and a_pow != n-1: return False return True magic = [0, 1, 0, 0, 3, 0, 5, 0, 7, 7, 7, 0, 11, 0, 13, 7, 7, 0, 8, 0, 19, 19, 7, 0, 23, 23, 8, 8, 8, 0] N = int(input()) if N < 30: print(magic[N]) else: if N%8 == 1 and is_prime(N-8): print(14) else: print(8)