p=[n+1for n in range(7**6)if all(pow(b,n,n+1)<2for b in(3,5,7,13))] while 1:print p[input()]