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