#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main(){
  ll mod = 1000000007;
  ll n;
  ll m;
  cin >> n >> m;
  //ll ks=m/(n-1)
  if(n==1){
    cout << (m+1)%mod << endl;
    return 0;
  }
  
  ll sy = m+1;
  ll ma = sy%(n-1);
  ll ks = sy/(n-1);
  //  if(ma)ks++;
  ks++;
  cout << ((((sy+ma)%mod)*(ks%mod))%mod -sy%mod+mod)%mod<< endl;
  //  cout << (m+1)%mod*((m+1)/(n-1))%mod<< endl;
  return 0;
}

  