n,m=map(int,input().split()) def fib(n, a=1, b=0): return b if n < 1 else fib(n - 1, a + b, a) print(fib(n-1)%m)