n = int(input()) m = int(input()) s = n if n == 1: pass else: s *= n-1 n -= 1 while s%m != 0: s = s/m print(s)