n,p = map(int,input().split()) a = 1 for i in range(2,n+1): a*=i print((a**(a**a)//(a*p))%(10**9+7))