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