import math n,m = int(input().split()) print(math.factorial(n % m))