def fibonacci(num, n) i = 3; while i <= n num << num[i-1] + num[i-2] i += 1 end return i; end n, m = gets.split.map(&:to_i) num = [0, 0, 1] i = fibonacci(num, n) puts num[i-1] % m