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