ss = input().split() n = int(ss[0]) m = int(ss[1]) f = [0,1] for i in range(2,n): f.append(f[i - 1] + f[i - 2]) print(f[n - 1] % m)