n=int(input()) p=int(input()) a=1 b=1 c=0 if n==1 or n==2: c=1 else: for x in range(n-2): c=a*b a=b b=c print(c%p)