N, M = gets.split.map &:to_i if M == 1 0 else p (1..N).inject(1){|r, n| r * n % M } end