print((function (n, m) local l,r=0,1 for i=3,n do l,r=r,(r%m+l%m)%m end return r end)(io.stdin:read("*n"), io.stdin:read("*n")))