#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e12+7;
ll mul(ll a,ll b)
{
ll sum=0;
while(b)
{
if(b%2==1)
sum=(sum+a)%mod;
a=(a+a)%mod;
b=b/2;
}
return sum;
}
ll pre(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b%2==1)
ans=mul(ans,a)%mod;
a=mul(a,a)%mod;
b=b/2;
}
return ans;
}
int main()
{
ll n,m;
cin>>n>>m;
cout<<(pre(m,n)-mul(pre(m-1,n-1),m)+mod)%mod<<endl;
return 0;
}