def main(): n, m = [int(i) for i in input().split()] f_1 = 0 f_2 = 1 f = [f_1, f_2] for i in range(2, n): f_n = f[0] + f[1] f.append(f_n) f.remove(f[0]) ans = f[1] % m print(ans) if __name__ == "__main__": main()