#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
void setIO(const string& file_name) {
  freopen((file_name + ".in").c_str(), "r", stdin);
  freopen((file_name + ".out").c_str(), "w+", stdout);
}
long long m[2100000], low[2100000], vis[2100000], fac[2100000];
long long p[2100000], n, k, ans[2100000], contr[2100000];
long long bin_pow(long long a, long long b) {
  long long ans = 1ll;
  for (long long i = 0; (1 << (i)) <= b; i++) {
    if (b & (1 << (i))) {
      ans = (((ans) % mod * (a) % mod) % mod);
    }
    a = (((a) % mod * (a) % mod) % mod);
  }
  return ans;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  low[1] = mod;
  m[1] = p[1] = 1;
  for (int i = 2; i <= 2e6; i++) {
    if (vis[i]) continue;
    low[i] = i;
    if ((long long)i * (long long)i > 2e6) continue;
    for (int j = i; j <= 2e6; j += i) {
      if (!vis[j]) low[j] = i;
      vis[j] = 1;
    }
  }
  for (int i = 2; i <= 2e6; i++) {
    assert(low[i]);
    if (low[i] == i)
      m[i] = -1;
    else if ((i / low[i]) % low[i] == 0)
      m[i] = 0;
    else
      m[i] = m[i / low[i]] * -1;
  }
  cin >> n >> k;
  for (int i = 2; i <= k; i++) {
    if (low[i] == i)
      p[i] = bin_pow(i, n);
    else
      p[i] = (((p[low[i]]) % mod * (p[i / low[i]]) % mod) % mod);
  }
  long long tot = 0ll;
  for (int i = 1; i <= k; i++) {
    ans[i] = ans[i - 1];
    int ind = 0;
    for (int j = i; j; j /= low[j]) {
      if ((j / low[j]) % low[j] != 0 && j != 1) {
        fac[ind++] = low[j];
      }
    }
    for (int b = 0; b < (1 << (ind)); b++) {
      int x = 1;
      for (int j = 0; j < ind; j++)
        if (b & (1 << (j))) x *= fac[j];
      ans[i] += mod - contr[x];
      contr[x] = ((m[x] * p[i / x]) + mod) % mod;
      ans[i] += mod + contr[x];
    }
    ans[i] %= mod;
    tot += ans[i] ^ (long long)i;
  }
  cout << tot % mod << '\n';
  return 0;
}
