def main(): N, M = map(int, input().split()) before, current = 0, 1 for _ in range(3, N+1): before, current = (current) % M, (before + current) % M print(current) if __name__ == "__main__": main()