N, M = gets.split.map(&:to_i) ans = 1 (1..N).each do |i| ans = ans * i % M end puts ans