def fib(n) a = 0 b = 1 (n - 2).times{ a, b = b, (a + b) % M } b end N, M = gets.split.take(2).map(&:to_i) p fib(N) % M