#include <bits/stdc++.h>
using namespace std;
long long powM(long long a, int t = 1000000007 - 2) {
  long long ans = 1;
  while (t) {
    if (t & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007;
    t >>= 1;
  }
  return ans;
}
int n, L, mu[2000500], tn, p[2000500 >> 3];
long long id[2000500], ans[2000500];
int main() {
  scanf("%d%d", &n, &L);
  id[1] = mu[1] = 1;
  for (int i = 2; i <= L; i++) {
    if (!id[i]) {
      mu[p[++tn] = i] = -1;
      id[i] = powM(i, n);
    }
    for (int j = 1, t; j <= tn && (t = i * p[j]) <= L; j++) {
      id[t] = id[i] * id[p[j]] % 1000000007;
      if (i % p[j] == 0) break;
      mu[t] = -mu[i];
    }
  }
  for (int i = 1; i <= L; i++)
    for (int j = 1; i * j <= L; j++) ans[i * j] += (id[j] - id[j - 1]) * mu[i];
  long long tot = 0;
  for (int i = 1; i <= L; i++) {
    ans[i] = (ans[i - 1] + ans[i] % 1000000007 + 1000000007) % 1000000007;
    tot += ans[i] ^ i;
  }
  printf("%I64d", tot % 1000000007);
  return 0;
}
