# frozen_string_literal: true n, m = gets.chomp.split.map(&:to_i) def fib(num) i = 0 b = 1 c = 0 while i < num a = b b = c c = a + b i += 1 end c end # ref: https://ja.wikipedia.org/% # wiki/%E3%83%95%E3%82%A3%E3%83%9C%E3%83%8A%E3%83%83%E3%83%81%E6%95%B0 p fib(n - 1) % m