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