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