from math import comb N, M = map(int, input().split()) if N % 3 != 0: print(0) else: print(comb(N, N // 3) // (N * 2 // 3 + 1) % M)