# -*- coding: utf-8 -*- import math #------- # Initialize N,M = map(int, input().split()) #------- # Define def fib(n): ans, n1, n2 = 1, 0, 1 if n == 0: return n1 if n == 1: return n2 for i in range(2, n): ans = (n1 + n2) % M n1 = n2 n2 = ans return ans #------- # Do #------- # Output print(fib(N) % M)