# coding: utf-8 n, m = map(int, input().split()) f1 = 0 f2 = 1 fb = 0 for _ in range(3, n + 1): fb = (f1 + f2) % m f1 = f2 f2 = fb print(fb)