#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b;
vector<pair<int, int> > vec[3];
void Build() {
  vec[0].push_back({1, 2});
  vec[1].push_back({3, 3});
  vec[2].push_back({4, 4});
  vec[1].push_back({5, 6});
  vec[2].push_back({7, 8});
  vec[0].push_back({9, 12});
  vec[1].push_back({13, 14});
  vec[2].push_back({15, 18});
  vec[0].push_back({19, 26});
  vec[1].push_back({27, 38});
  vec[2].push_back({39, 39});
  vec[0].push_back({40, 56});
  vec[2].push_back({57, 57});
  vec[1].push_back({58, 80});
  vec[2].push_back({81, 84});
  vec[0].push_back({85, 119});
  vec[2].push_back({120, 120});
  vec[1].push_back({121, 173});
  vec[2].push_back({174, 178});
  vec[0].push_back({179, 254});
  vec[2].push_back({255, 259});
  vec[1].push_back({260, 362});
  vec[2].push_back({363, 381});
  vec[0].push_back({382, 536});
  vec[2].push_back({537, 543});
  vec[1].push_back({544, 779});
  vec[2].push_back({780, 804});
  vec[0].push_back({805, 1145});
  vec[2].push_back({1146, 1168});
  vec[1].push_back({1169, 1631});
  vec[2].push_back({1632, 1717});
  vec[0].push_back({1718, 2414});
  vec[2].push_back({2415, 2446});
  vec[1].push_back({2447, 3506});
  vec[2].push_back({3507, 3621});
  vec[0].push_back({3622, 5153});
  vec[2].push_back({5154, 5259});
  vec[1].push_back({5260, 7340});
  vec[2].push_back({7341, 7729});
  vec[0].push_back({7730, 10865});
  vec[2].push_back({10866, 11010});
  vec[1].push_back({11011, 15779});
  vec[2].push_back({15780, 16297});
  vec[0].push_back({16298, 23189});
  vec[2].push_back({23190, 23668});
  vec[1].push_back({23669, 33032});
  vec[2].push_back({33033, 34783});
  vec[0].push_back({34784, 48893});
  vec[2].push_back({48894, 49548});
  vec[1].push_back({49549, 71006});
  vec[2].push_back({71007, 73339});
  vec[0].push_back({73340, 104351});
  vec[2].push_back({104352, 106509});
  vec[1].push_back({106510, 148646});
  vec[2].push_back({148647, 156526});
  vec[0].push_back({156527, 220019});
  vec[2].push_back({220020, 222969});
  vec[1].push_back({222970, 319529});
  vec[2].push_back({319530, 330028});
  vec[0].push_back({330029, 469580});
  vec[2].push_back({469581, 479293});
  vec[1].push_back({479294, 668909});
  vec[2].push_back({668910, 704370});
  vec[0].push_back({704371, 990086});
  vec[2].push_back({990087, 1003363});
  vec[1].push_back({1003364, 1437881});
  vec[2].push_back({1437882, 1485129});
  vec[0].push_back({1485130, 2113112});
  vec[2].push_back({2113113, 2156821});
  vec[1].push_back({2156822, 3010091});
  vec[2].push_back({3010092, 3169668});
  vec[0].push_back({3169669, 4455389});
  vec[2].push_back({4455390, 4515136});
  vec[1].push_back({4515137, 6470465});
  vec[2].push_back({6470466, 6683083});
  vec[0].push_back({6683084, 9509006});
  vec[2].push_back({9509007, 9705697});
  vec[1].push_back({9705698, 13545410});
  vec[2].push_back({13545411, 14263509});
  vec[0].push_back({14263510, 20049251});
  vec[2].push_back({20049252, 20318115});
  vec[1].push_back({20318116, 29117093});
  vec[2].push_back({29117094, 30073876});
  vec[0].push_back({30073877, 42790529});
  vec[2].push_back({42790530, 43675639});
  vec[1].push_back({43675640, 60954347});
  vec[2].push_back({60954348, 64185793});
  vec[0].push_back({64185794, 90221630});
  vec[2].push_back({90221631, 91431520});
  vec[1].push_back({91431521, 131026919});
  vec[2].push_back({131026920, 135332445});
  vec[0].push_back({135332446, 192557381});
  vec[2].push_back({192557382, 196540378});
  vec[1].push_back({196540379, 274294562});
  vec[2].push_back({274294563, 288836071});
  vec[0].push_back({288836072, 405997337});
  vec[2].push_back({405997338, 411441843});
  vec[1].push_back({411441844, 589621136});
  vec[2].push_back({589621137, 608996005});
  vec[0].push_back({608996006, 866508215});
  vec[2].push_back({866508216, 884431704});
  vec[1].push_back({884431705, 1000000000});
}
long long dp[MAXN][4], cnt[3];
long long f(long long x) {
  long long res = x * m - x * (x + 1) / 2;
  return res % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Build();
  cin >> n >> m;
  for (int i : {0, 1, 2}) {
    for (pair<int, int> p : vec[i])
      if (p.first <= m) cnt[i] += f(min(m, p.second)) - f(p.first - 1);
    cnt[i] %= mod;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j : {0, 1, 2, 3})
      for (int k : {0, 1, 2}) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j ^ k] * cnt[k]) % mod;
      }
  long long ans = (dp[n][1] + dp[n][2] + dp[n][3]) % mod;
  if (ans < 0) ans += mod;
  cout << ans << '\n';
  return 0;
}
