N,M = map(int,input().split()) memo = {} def f(x): if x==1: return 0 if x==2: return 1 if x in memo: return memo[x] memo[x] = (f(x-1)+f(x-2))%M return memo[x] print(f(N))