num = gets.split(' ').map{|i| i.to_i} fact = num[0] mod = num[1] multi = 1 if fact >= mod then puts 0 else 1.upto(fact) do |i| multi = multi * i % mod if multi == 0 then break end end puts multi end