#include <bits/stdc++.h>
using namespace std;
bool f[2000010 + 10];
long long mu[2000010 + 10], p[2000010 + 10], pnum, n, k, ans[2000010];
vector<long long> num[2000010 + 10];
long long read() {
  long long tmp = 0, fh = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    tmp = tmp * 10 + ch - '0';
    ch = getchar();
  }
  return tmp * fh;
}
long long mypow(long long x, long long y) {
  long long i = x;
  x = 1;
  while (y > 0) {
    if (y % 2 == 1) x = x * i % 1000000007;
    i = i * i % 1000000007;
    y /= 2;
  }
  return x;
}
void getmu() {
  f[1] = true;
  mu[1] = 1;
  for (long long i = 2; i <= 2000010; i++) {
    if (f[i] == false) p[++pnum] = i, mu[i] = -1;
    for (long long j = 1; j <= pnum && 2000010 / p[j] >= i; j++) {
      f[i * p[j]] = true;
      if (i % p[j] == 0) {
        mu[i * p[j]] = 0;
        break;
      } else
        mu[i * p[j]] = mu[i] * mu[p[j]];
    }
  }
}
int main() {
  getmu();
  cin >> n >> k;
  for (long long i = 1; i <= 2000010; i++) p[i] = mypow(i, n);
  for (long long i = 1; i <= k; i++)
    for (long long j = i; j <= k; j += i)
      ans[j] =
          ((ans[j] - mu[i] * p[(j - 1) / i] + mu[i] * p[j / i]) % 1000000007 +
           1000000007) %
          1000000007;
  ans[0] = 0;
  for (long long i = 1; i <= k; i++) {
    ans[i] = (ans[i - 1] + ans[i]) % 1000000007;
    ans[0] = (ans[0] + (ans[i] ^ i)) % 1000000007;
  }
  cout << ans[0] << endl;
  return 0;
}
