#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int MOD = 1e9 + 7;
bool mark[N];
vector<int> ps, corporator[N];
int primeMul[N], primeCnt[N], nthPower[N], b[N], n, k;
int _sum(int, int);
int _mul(int, int);
int _pow(int, int);
void _push(int&, int);
int main() {
  cin >> n >> k;
  fill(primeMul, primeMul + k + 1, 1);
  for (int i = 1; i <= k; i++) {
    nthPower[i] = _pow(i, n);
    if (i > 1 && !mark[i]) {
      for (int j = i; j <= k; j += i) {
        mark[j] = true;
        primeMul[j] *= i;
        primeCnt[j]++;
      }
    }
    if (primeMul[i] == i) ps.push_back(i);
  }
  for (int i : ps)
    for (int j = i; j <= k; j += i) corporator[j].push_back(i);
  b[1] = nthPower[1];
  int ans = b[1] ^ 1;
  for (int i = 2; i <= k; i++) {
    b[i] = b[i - 1];
    for (int c : corporator[i]) {
      int v = _sum(MOD - nthPower[(i - 1) / c], nthPower[i / c]);
      _push(b[i], primeCnt[c] & 1 ? MOD - v : v);
    }
    _push(ans, b[i] ^ i);
  }
  cout << ans << endl;
}
int _sum(int a, int b) { return a + b - (a + b >= MOD ? MOD : 0); }
int _mul(int a, int b) { return 1LL * a * b % MOD; }
int _pow(int a, int b) {
  if (!b) return 1;
  int res = _pow(a, b >> 1);
  res = _mul(res, res);
  if (b & 1) res = _mul(res, a);
  return res;
}
void _push(int& a, int b) { a = _sum(a, b); }
