import sys input=lambda: sys.stdin.readline().rstrip() n,m=map(int,input().split()) a,b=0,1 for _ in range(n-2): a,b=b,a+b if b>m: b%=m print(b%m)