#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e6;
int sp[MAXN + 1];
inline int lgput(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1) ans = (1LL * ans * a) % MOD;
    b >>= 1;
    a = (1LL * a * a) % MOD;
  }
  return ans;
}
char bad[MAXN + 1];
bool ciur[MAXN + 1];
inline void mod(int &x) {
  if (x >= MOD) x -= MOD;
}
int aux[MAXN + 1];
int main() {
  int i, n, k, j;
  ios::sync_with_stdio(false);
  cin >> n >> k;
  memset(bad, -1, sizeof(bad));
  for (i = 2; i <= k; i++) {
    if (ciur[i] == 0) {
      for (long long x = 1LL * i * i; x <= k; x += i * i) bad[x] = 0;
      for (j = i; j <= k; j += i) {
        bad[j] *= -1;
        ciur[j] = 1;
      }
    }
  }
  for (i = 1; i <= k; i++) {
    aux[i] = lgput(i, n);
  }
  for (i = 2; i <= k; i++) {
    if (bad[i] != 0) {
      int val = 1;
      for (j = i; j <= k; j += i) {
        sp[j] += (aux[val] - aux[val - 1]) * bad[i];
        if (sp[j] < 0)
          sp[j] += MOD;
        else
          mod(sp[j]);
        val++;
      }
    }
  }
  for (i = 1; i <= k; i++) {
    sp[i] += sp[i - 1];
    mod(sp[i]);
  }
  int ans = 0;
  for (i = 1; i <= k; i++) {
    sp[i] = lgput(i, n) - sp[i] + MOD;
    mod(sp[i]);
    ans += (sp[i] ^ i);
    mod(ans);
  }
  cout << ans;
  return 0;
}
