N, M = STDIN.gets.strip.split.map(&:to_i) f1 = 0 f2 = 1 fb = 0 (3 .. N).each do fb = (f1 + f2) % M f1 = f2 f2 = fb end puts fb