ss = input().split() n = int(ss[0]) m = int(ss[1]) fa = 0 fb = 1 fc = 0 for i in range(n - 2): fc = (fa + fb) % m fa = fb fb = fc print(fc % m)