#include <bits/stdc++.h>
using namespace std;
vector<int> L0 = {1,         9,        19,       40,       85,       179,
                  382,       805,      1718,     3622,     7730,     16298,
                  34784,     73340,    156527,   330029,   704371,   1485130,
                  3169669,   6683084,  14263510, 30073877, 64185794, 135332446,
                  288836072, 608996006};
vector<int> R0 = {2,         12,       26,       56,       119,      254,
                  536,       1145,     2414,     5153,     10865,    23189,
                  48893,     104351,   220019,   469580,   990086,   2113112,
                  4455389,   9509006,  20049251, 42790529, 90221630, 192557381,
                  405997337, 866508215};
vector<int> L1 = {3,         5,         13,       27,       58,       121,
                  260,       544,       1169,     2447,     5260,     11011,
                  23669,     49549,     106510,   222970,   479294,   1003364,
                  2156822,   4515137,   9705698,  20318116, 43675640, 91431521,
                  196540379, 411441844, 884431705};
vector<int> R1 = {
    3,        6,        14,        38,        80,        173,       362,
    779,      1631,     3506,      7340,      15779,     33032,     71006,
    148646,   319529,   668909,    1437881,   3010091,   6470465,   13545410,
    29117093, 60954347, 131026919, 274294562, 589621136, 1000000000};
vector<int> L2 = {
    4,        7,         15,        39,        57,        81,        120,
    174,      255,       363,       537,       780,       1146,      1632,
    2415,     3507,      5154,      7341,      10866,     15780,     23190,
    33033,    48894,     71007,     104352,    148647,    220020,    319530,
    469581,   668910,    990087,    1437882,   2113113,   3010092,   4455390,
    6470466,  9509007,   13545411,  20049252,  29117094,  42790530,  60954348,
    90221631, 131026920, 192557382, 274294563, 405997338, 589621137, 866508216};
vector<int> R2 = {
    4,        8,         18,        39,        57,        84,        120,
    178,      259,       381,       543,       804,       1168,      1717,
    2446,     3621,      5259,      7729,      11010,     16297,     23668,
    34783,    49548,     73339,     106509,    156526,    222969,    330028,
    479293,   704370,    1003363,   1485129,   2156821,   3169668,   4515136,
    6683083,  9705697,   14263509,  20318115,  30073876,  43675639,  64185793,
    91431520, 135332445, 196540378, 288836071, 411441843, 608996005, 884431704};
const int mod = 1e9 + 7;
const int N = 1005;
int dp[N][4];
int n, p;
int ways[3];
int solve(int i, int Xor) {
  if (i > n) return Xor > 0;
  if (dp[i][Xor] != -1) return dp[i][Xor];
  int ans = 0;
  for (int f = 0; f < 3; f++) {
    ans += 1ll * solve(i + 1, Xor ^ f) * ways[f] % mod;
    ans %= mod;
  }
  return dp[i][Xor] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  p--;
  vector<vector<int>> L, R;
  L = {L0, L1, L2};
  R = {R0, R1, R2};
  for (int f = 0; f < 3; f++) {
    int sz = L[f].size();
    for (int i = 0; i < sz; i++) {
      int l = L[f][i], r = R[f][i];
      if (l > p) continue;
      r = min(r, p);
      long long cur = 1ll * (r - l + 1) * (2 * p + 2 - r - l) / 2;
      ways[f] += cur % mod;
      ways[f] %= mod;
    }
  }
  memset(dp, -1, sizeof dp);
  cout << solve(1, 0) << endl;
  return 0;
}
