n,m=map(int,input().split()) a,b=34,55 #m>=10 for _ in '1'*(n-10):a,b=b,(a+b)%m print(a%m)