#include <bits/stdc++.h>
using namespace std;
const long long mm = 1e9 + 7;
const int maxn = 2005000;
int tot, n, k;
long long f[maxn], mu[maxn], pri[maxn], val[maxn];
int vis[maxn];
long long Pow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % mm;
    x = x * x % mm;
    y /= 2;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  int N = 2000000;
  mu[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (!vis[i]) pri[++tot] = i, mu[i] = -1;
    for (int j = 1; j <= tot && i * pri[j] <= N; j++) {
      vis[i * pri[j]] = 1;
      if (i % pri[j])
        mu[i * pri[j]] = -mu[i];
      else {
        mu[i * pri[j]] = 0;
        break;
      }
    }
  }
  for (int i = 1; i <= k; i++) val[i] = Pow(i, n);
  for (int i = 1; i <= k; i++)
    if (mu[i]) {
      for (int j = 0, t = 0; j <= k; t++, j += i) {
        (f[j] += val[t] * mu[i] % mm) %= mm;
        if (j + i <= k) (f[j + i] += mm - val[t] * mu[i] % mm) %= mm;
      }
    }
  for (int i = 1; i <= k; i++) f[i] = (f[i - 1] + f[i] + mm) % mm;
  long long ans = 0;
  for (int i = 1; i <= k; i++) (ans += f[i] ^ i) %= mm;
  printf("%lld\n", ans);
  return 0;
}
