#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 7, Mod = 1000000000 + 7;
const int R[] = {
    3,         4,         5,         7,         9,         13,
    15,        19,        27,        39,        40,        57,
    58,        81,        85,        120,       121,       174,
    179,       255,       260,       363,       382,       537,
    544,       780,       805,       1146,      1169,      1632,
    1718,      2415,      2447,      3507,      3622,      5154,
    5260,      7341,      7730,      10866,     11011,     15780,
    16298,     23190,     23669,     33033,     34784,     48894,
    49549,     71007,     73340,     104352,    106510,    148647,
    156527,    220020,    222970,    319530,    330029,    469581,
    479294,    668910,    704371,    990087,    1003364,   1437882,
    1485130,   2113113,   2156822,   3010092,   3169669,   4455390,
    4515137,   6470466,   6683084,   9509007,   9705698,   13545411,
    14263510,  20049252,  20318116,  29117094,  30073877,  42790530,
    43675640,  60954348,  64185794,  90221631,  91431521,  131026920,
    135332446, 192557382, 196540379, 274294563, 288836072, 405997338,
    411441844, 589621137, 608996006, 866508216, 884431705, 1000000001,
    1000000002};
const int tot[] = {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};
int n, p, f[4], Dp[N][4], Last = 1;
inline void Inc(int& A, int B) {
  A += B;
  A >= Mod ? A -= Mod : A;
}
inline int Mul(int A, int B) { return 1ll * A * B % Mod; }
inline int Get(int l, int r, int x) { return 1ll * (l + r) * x / 2 % Mod; }
int main() {
  scanf("%d%d", &n, &p);
  for (int i = (0), iLimit = (107); i <= iLimit; (++(i))) {
    int t = min(p, R[i] - 1);
    Inc(f[tot[i]], Get(p - Last, p - t, t - Last + 1)), Last = R[i];
    if (t == p) break;
  }
  Dp[0][0] = 1;
  for (int i = (1), iLimit = (n); i <= iLimit; (++(i)))
    for (int j = (0), jLimit = (3); j <= jLimit; (++(j)))
      for (int k = (0), kLimit = (3); k <= kLimit; (++(k)))
        Inc(Dp[i][j], Mul(Dp[i - 1][j ^ k], f[k]));
  int Ans = 0;
  for (int i = (1), iLimit = (3); i <= iLimit; (++(i))) Inc(Ans, Dp[n][i]);
  printf("%d", Ans);
  return 0;
}
