import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, M = mapint() old = 0 new = 1 for i in range(2, N): new, old = old+new, new new %= M old %= M print(new)