def fib(n, mod) a, b = 0, 1 (n - 1).times do a, b = b, (a + b) % mod end a end N, M = gets.split.map(&:to_i) puts fib(N, M)