#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
long long dp[1005][4];
long long ways[3];
pair<long long, long long> sprague[] = {
    {0, 2},        {1, 1},         {2, 1},        {1, 2},
    {2, 2},        {0, 4},         {1, 2},        {2, 4},
    {0, 8},        {1, 12},        {2, 1},        {0, 17},
    {2, 1},        {1, 23},        {2, 4},        {0, 35},
    {2, 1},        {1, 53},        {2, 5},        {0, 76},
    {2, 5},        {1, 103},       {2, 19},       {0, 155},
    {2, 7},        {1, 236},       {2, 25},       {0, 341},
    {2, 23},       {1, 463},       {2, 86},       {0, 697},
    {2, 32},       {1, 1060},      {2, 115},      {0, 1532},
    {2, 106},      {1, 2081},      {2, 389},      {0, 3136},
    {2, 145},      {1, 4769},      {2, 518},      {0, 6892},
    {2, 479},      {1, 9364},      {2, 1751},     {0, 14110},
    {2, 655},      {1, 21458},     {2, 2333},     {0, 31012},
    {2, 2158},     {1, 42137},     {2, 7880},     {0, 63493},
    {2, 2950},     {1, 96560},     {2, 10499},    {0, 139552},
    {2, 9713},     {1, 189616},    {2, 35461},    {0, 285716},
    {2, 13277},    {1, 434518},    {2, 47248},    {0, 627983},
    {2, 43709},    {1, 853270},    {2, 159577},   {0, 1285721},
    {2, 59747},    {1, 1955329},   {2, 212618},   {0, 2825923},
    {2, 196691},   {1, 3839713},   {2, 718099},   {0, 5785742},
    {2, 268864},   {1, 8798978},   {2, 956783},   {0, 12716653},
    {2, 885110},   {1, 17278708},  {2, 3231446},  {0, 26035837},
    {2, 1209890},  {1, 39595399},  {2, 4305526},  {0, 57224936},
    {2, 3982997},  {1, 77754184},  {2, 14541509}, {0, 117161266},
    {2, 5444506},  {1, 178179293}, {2, 19374869}, {0, 257512210},
    {2, 17923489}, {1, 257512210}};
int main() {
  long long n, k;
  cin >> n >> k;
  dp[0][0] = 1;
  dp[0][1] = dp[0][2] = dp[0][3] = 0;
  long long total = 0;
  ways[0] = ways[1] = ways[2] = 0;
  for (int i = 0; total <= k; ++i) {
    if (total + sprague[i].second <= k) {
      long long x1 = (k - total) * sprague[i].second -
                     sprague[i].second * (sprague[i].second + 1) / 2;
      ways[sprague[i].first] += x1 % p;
      ways[sprague[i].first] %= p;
      total += sprague[i].second;
    } else {
      sprague[i].second = k - total;
      long long x1 = (k - total) * sprague[i].second -
                     sprague[i].second * (sprague[i].second + 1) / 2;
      ways[sprague[i].first] += x1 % p;
      ways[sprague[i].first] %= p;
      break;
    }
  }
  for (int i = 1; i <= 1000; ++i) {
    dp[i][0] = dp[i][1] = dp[i][2] = dp[i][3] = 0;
    for (int j = 0; j <= 3; ++j)
      for (int k = 0; k <= 3; ++k) {
        dp[i][j ^ k] += dp[i - 1][j] * ways[k];
        dp[i][j ^ k] %= p;
      }
  }
  cout << (dp[n][1] + dp[n][2] + dp[n][3]) % p << endl;
}
