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 if p!=0: print(c%p) else: print(0)