# -*- coding: utf-8 -*- import sys,math def isprime(q): if q==2: return True if q<2 or q&1==0: return False return pow(2,q-1,q)==1 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,25] x=input() if x<=25: print a[x] elif (x-1)%8==0 and isprime(x-8): print 14 else: print 8