#include <bits/stdc++.h>
using namespace std;
const int M = 1005, P = (int)1e9 + 7;
void Add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
struct W {
  int v, r;
} a[M], b[M];
int asz, bsz;
int n, p;
struct T {
  int l, r, v;
} c[M];
int csz;
int calc(int x, int y) {
  if (x > y) swap(x, y);
  if (x == 0) {
    if (y == 1) return 2;
    return 1;
  } else
    return 0;
}
void add(int v, int r) {
  int rra = min((long long)p, (long long)r * 3 + 2),
      rrb = min((long long)p, (long long)r * 3 / 2);
  if (v == a[asz - 1].v)
    a[asz - 1].r = rra;
  else if (rra != a[asz - 1].r)
    a[asz++] = (W){v, rra};
  if (v == b[bsz - 1].v)
    b[bsz - 1].r = rrb;
  else if (rrb != b[bsz - 1].r)
    b[bsz++] = (W){v, rrb};
}
void init() {
  a[asz++] = (W){0, 8};
  b[bsz++] = (W){0, 3};
  c[csz++] = (T){1, min(2, p), 0};
  for (int i = 3, r, aa = 0, bb = 0, sg; i <= p; i = r + 1) {
    while (a[aa].r < i) aa++;
    while (b[bb].r < i) bb++;
    r = min(a[aa].r, b[bb].r);
    sg = calc(a[aa].v, b[bb].v);
    c[csz++] = (T){i, r, sg};
    add(sg, r);
  }
}
int dp[3], pd[M][4];
int main() {
  scanf("%d %d", &n, &p);
  init();
  for (int i = 0; i < csz; i++)
    dp[c[i].v] = (dp[c[i].v] + (long long)(p - c[i].r + p - c[i].l) *
                                   (c[i].r - c[i].l + 1) / 2) %
                 P;
  pd[0][0] = 1;
  for (int p = 0, i = 1; i <= n; i++, p++)
    for (int j = 0; j < 4; j++)
      if (pd[p][j])
        for (int k = 0; k < 3; k++)
          Add(pd[i][j ^ k], (long long)pd[p][j] * dp[k] % P);
  printf("%d\n", (int)(((long long)pd[n][1] + pd[n][2] + pd[n][3]) % P));
  return 0;
}
