def fib(n,f0,f1): #print ('n=',n) #print ('f0=', f0) if n == 0: #print (f0) return f0 else: tmp = f1 f1 += f0 f0 = tmp n -= 1 f0 = fib(n,f0,f1) return f0 n, m = list(map(int, input().split())) f0 = 0 f1 = 1 f = fib(n-1,f0,f1) #print (f) print (f%m)