def main(): N, M = map(int, input().split()) print(get_fib_value(N) % M) def get_fib_value(term_num): #if term_num == 0: # return 0 #elif term_num == 1: # return 1 #else: # return get_fib_value(term_num - 1) + get_fib_value(term_num - 2) #last_value = 0 #value = 1 #for i in range(2, term_num): # tmp = value # value = value + last_value # last_value = tmp #return value a, b = 0, 1 for _ in range(term_num-1): a, b = b, b + a return a if __name__ == '__main__': main()