#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], answers[ulim], sub[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;
}
void pre(long long lim, long long n) {
  coeff[1] = 1;
  for (long long i = 1; i < lim + 1; i++)
    for (long long j = i + i; j < lim + 1; j += i)
      coeff[j] = (coeff[j] - coeff[i] + mod) % mod;
  for (long long i = 1; i < ulim; i++) powers[i] = fastexpo(i, n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  pre(k, n);
  for (long long i = 1; i <= k; i++)
    for (long long j = i; j <= k; j += i) {
      answers[j] += (coeff[i] * powers[j / i]) % mod;
      sub[j] += (coeff[i] * powers[j / i - 1]) % mod;
    }
  answers[1] %= mod;
  for (long long i = 2; i <= k; i++)
    answers[i] %= mod, sub[i] %= mod,
        (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;
}
