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