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