#include<bits/stdc++.h>
const long long maxn=50001,mod=1e9+7;
inline const void read(long long &a)
{
a=0;
char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
}
inline const void write(long long a)
{
if(a>=10)write(a/10);
putchar(a%10+'0');
}
long long n,m,a[maxn],ans=0,sum;
inline long long fast_pow(long long x,long long y)
{
long long base=x,k=y,res=1;
while(k)
{
if(k&1)res=(res*base)%mod;
k>>=1;
base=(base*base)%mod;
}
return res;
}
int main()
{
read(n);read(m);
ans=(ans+m)%mod;
for(long long i=2;i<=n;i++)
{
long long c=fast_pow(i,m);
ans=(ans+i*(c-1)/(i-1))%mod;
}
write(ans);
return 0;
}