#include<cstdio>
#define ll long long
int p=1e9+7;
ll fastpow(ll x,ll k)
{
ll b=1;
while (k>0)
{
if (k%2==1)
b=(b*x)%p;
k=k/2;
x=(x*x)%p;
}
b=b%p;
return b;
}
int n,m;
int main(){
scanf("%d%d",&n,&m);ll sum=m;
for(int i=2;i<=n;i++)
{
ll w=fastpow(i,m);
sum+=((i*((w-1+p)%p))%p*fastpow(i-1,p-2))%p;
sum%=p;
}
printf("%d",int(sum));
}
ax ≡ 1 (mod b)
b^-1x≡1
a,b互质
x^b-1≡ 1(mod b)
a*x^-1(mod b)=a*x^b-2(mod b)