#include <bits/stdc++.h>
using namespace std;
long long n, m = 102, p;
const long long N = 1005, M = 105;
const long long mod = 1e9 + 7;
long long pos[M] = {
    0,         2,         3,         4,         6,         8,         12,
    14,        18,        26,        38,        39,        56,        57,
    80,        84,        119,       120,       173,       178,       254,
    259,       362,       381,       536,       543,       779,       804,
    1145,      1168,      1631,      1717,      2414,      2446,      3506,
    3621,      5153,      5259,      7340,      7729,      10865,     11010,
    15779,     16297,     23189,     23668,     33032,     34783,     48893,
    49548,     71006,     73339,     104351,    106509,    148646,    156526,
    220019,    222969,    319529,    330028,    469580,    479293,    668909,
    704370,    990086,    1003363,   1437881,   1485129,   2113112,   2156821,
    3010091,   3169668,   4455389,   4515136,   6470465,   6683083,   9509006,
    9705697,   13545410,  14263509,  20049251,  20318115,  29117093,  30073876,
    42790529,  43675639,  60954347,  64185793,  90221630,  91431520,  131026919,
    135332445, 192557381, 196540378, 274294562, 288836071, 405997337, 411441843,
    589621136, 608996005, 866508215, 884431704, 1000000000};
long long val[M] = {0, 0, 1, 2, 1, 2, 0, 1, 2, 0, 1, 2, 0, 2, 1, 2, 0, 2,
                    1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2,
                    0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2,
                    1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2,
                    0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2,
                    1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1};
long long dp[N][4], bs[3];
long long gs(long long l, long long r) {
  r = min(r, p);
  if (l > r) return 0;
  return (p - l + 1 + p - r + 1) * (r - l + 1) / 2;
}
void add(long long &x, long long y) { x = (x + y) % mod; }
signed main() {
  cin >> n >> p;
  p--;
  for (long long i = 1; i <= m; i++) {
    add(bs[val[i]], gs(pos[i - 1] + 1, pos[i]));
  }
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j <= 3; j++)
      for (long long t = 0; t <= 3; t++)
        if ((j ^ t) < 3) add(dp[i][j], dp[i - 1][t] * bs[j ^ t] % mod);
  for (long long i = 1; i <= n; i++) {
  }
  cout << (dp[n][1] + dp[n][2] + dp[n][3]) % mod;
  return 0;
}
