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