N, M = map(int, input().split()) a = [0, 1] + [0] * N for i in range(N): a[i+2] = a[i+1] + a[i] print(a[N-1] % M)