n, m = map(int, raw_input().split()) prepre = 0 pre = 1 for i in range(n - 2): now = prepre + pre prepre = pre pre = now print(pre % m)