n, m = gets.split.map(&:to_i) a = 0 b = 1 c = 0 (3..n).each do |i| c = a + b a = b b = c end p c % m