#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const long long mod = 1e9 + 7;
const long long ulim = 2e6 + 5;
long long coeff[ulim], powers[ulim], sub[ulim], answers[ulim];
long long fastexpo(long long n, long long p) {
  n %= mod;
  return (p == 0 ? 1 : fastexpo(n * n, p / 2) * (p & 1 ? n : 1)) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  coeff[1] = 1;
  for (long long i = 1; i <= k; i++) powers[i] = fastexpo(i, n);
  long long mx = 0;
  for (long long i = 1; i <= k; i++)
    for (long long j = i; j <= k; j += i) {
      if (j > i) coeff[j] = (coeff[j] - coeff[i]);
      mx = max(mx, coeff[j]);
      answers[j] += coeff[i] * powers[j / i];
      sub[j] += coeff[i] * powers[j / i - 1];
    }
  for (long long i = 1; i <= k; i++) {
    answers[i] %= mod, sub[i] %= mod;
    while (answers[i] < 0) answers[i] += mod;
    while (sub[i] < 0) sub[i] += mod;
  }
  for (long long i = 2; i <= k; i++)
    (answers[i] += answers[i - 1] + mod - sub[i]) %= mod;
  long long ans = 0;
  for (long long i = 1; i <= k; i++) (ans += (answers[i] ^ i)) %= mod;
  cout << ans << endl;
}
