#include<cstdio>
#define ll long long
#define mo 1000000007
usingnamespace std;
ll n,m,r;
ll ksm(ll a,ll b) { for (r=1;b;b>>=1,a=a*a%mo) if (b&1) r=r*a%mo; return r; }
int main()
{
freopen("color.in","r",stdin),freopen("color.out","w",stdout),scanf("%lld%lld",&n,&m);
printf("%lld
",(ksm(m-1,n)+(m-1)*ksm(-1,n))%mo);
return0;
}