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