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