#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

const ll MOD=1000000007;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  ll n,m;
	      	  cin >> n >> m;

	      	  if(n==1){
	      		  cout << (m+1)%MOD << endl;
	      		  return 0;
	      	  }

	      	  ll ans=0;
	      	  ll N=m/(n-1LL);

	      	  ans=(((2*m+2)%MOD)*(N%MOD))%MOD;
	      	  ll u=(((n-1)%MOD)*(N%MOD))%MOD;
	      	  u=(u*((N+1)%MOD))%MOD;
	      	  ans-=u;
	      	  ans+=(m+1)%MOD;

	      	  cout << (ans+MOD)%MOD << endl;



	          return 0;
}