#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
inline T gcd(T a, T b) {
  T c;
  while (b) {
    c = b;
    b = a % b;
    a = c;
  }
  return a;
}
const double PI = acos(-1);
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e6;
int mu[N + 5], pown[N + 5], lp[N + 5], ans[2 * N + 5];
vector<int> primes;
int n, k;
int modpow(int x, int y = n) {
  int res = 1;
  while (y) {
    if (y & 1) {
      res = (res * 1ll * x) % MOD;
    }
    y >>= 1;
    x = (x * 1ll * x) % MOD;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> k;
  clock_t timer = clock();
  mu[1] = 1;
  pown[1] = 1;
  for (int i = 2; i <= k; i++) {
    pown[i] = modpow(i);
    if (!lp[i]) {
      lp[i] = i;
      primes.emplace_back(i);
      mu[i] = -1;
    }
    for (int j = 0; j < (int)primes.size() && i * primes[j] <= k; j++) {
      lp[primes[j] * i] = primes[j];
      mu[primes[j] * i] = mu[i] * (i % primes[j] ? -1 : 0);
      if (i % primes[j] == 0) break;
    }
  }
  long long sum = 0, res = 0;
  for (int i = 1; i <= k; i++) {
    for (int m = i; m <= k; m += i) {
      ans[m] += mu[i] * pown[m / i];
      ans[m] -= (ans[m] >= MOD) * MOD;
      ans[m + i] -= mu[i] * pown[m / i];
      ans[m + i] += (ans[m + i] < 0) * MOD;
    }
    ans[i] %= MOD;
    if (ans[i] < 0) ans[i] += MOD;
    sum = (ans[i] + sum) % MOD;
    res = (res + (i ^ sum)) % MOD;
  }
  cout << (res + MOD) % MOD << "\n";
  timer = clock() - timer;
  return 0;
}
