#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 2e6 + 7;
const double EPS = 1e-8;
vector<long long> st, g, d, p;
long long n, k;
long long power(long long a, long long k) {
  if (!k) {
    return 1;
  }
  long long b = power(a, k / 2);
  b = b * b % INF;
  if (k % 2) {
    return a * b % INF;
  } else {
    return b;
  }
}
void init() {
  st.resize(MAXN, 0);
  g.resize(MAXN, 0);
  d.resize(MAXN, -1);
  for (int i = 0; i < MAXN; i++) {
    st[i] = power(i, n);
  }
  for (long long i = 2; i < MAXN; i++) {
    if (d[i] == -1) {
      d[i] = p.size();
      p.push_back(i);
    }
    for (long long j = 0; j <= d[i]; j++) {
      if (p[j] * i >= MAXN) break;
      d[p[j] * i] = j;
    }
  }
  g[1] = 1;
  for (long long i = 2; i < MAXN; i++) {
    long long cnt = 0, pr = -1;
    long long x = i;
    bool fl = false;
    while (x > 1) {
      if (pr == p[d[x]]) {
        fl = true;
        break;
      }
      cnt++;
      pr = p[d[x]];
      x /= p[d[x]];
    }
    if (!fl) {
      g[i] = (cnt % 2 ? -1 : 1);
    }
  }
}
long long sum = 0;
vector<long long> f(MAXN, 0);
void rec(long long pred, vector<pair<long long, long long> > &allp, long long x,
         long long now) {
  if (pred == allp.size()) {
    sum += INF - f[now] * g[now];
    f[now] = st[x / now];
    sum += f[now] * g[now];
    while (sum >= INF) {
      sum -= INF;
    }
    return;
  }
  for (long long i = 0; i <= allp[pred].second; i++) {
    rec(pred + 1, allp, x, now);
    now *= allp[pred].first;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  init();
  long long res = 0;
  for (long long i = 1; i <= k; i++) {
    vector<pair<long long, long long> > allp;
    long long pr = -1;
    long long x = i;
    while (x > 1) {
      if (p[d[x]] == pr) {
        allp.back().second++;
      } else {
        allp.push_back({p[d[x]], 1});
        pr = p[d[x]];
      }
      x /= p[d[x]];
    }
    rec(0, allp, i, 1);
    res += sum ^ i;
    res %= INF;
  }
  cout << res << "\n";
}
