## https://yukicoder.me/problems/no/526 def main(): N, M = map(int, input().split()) c = 0 d = 1 ans = 0 for _ in range(2, N): ans = (c + d) % M c = d d = ans print(ans) if __name__ == "__main__": main()