void main()
{
	int n,k,m,i;
	scanf("%d %d",&n,&k);
    if(n!=2){m=pow(n,n)-(n-1)*k;
	printf("%d",m);}
	else printf("%d",7);
}