#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
const int N = 2000000 + 10;
const int mod = 1e9 + 7;
inline int qpow(int a, int b) {
  int c = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) c = 1ll * c * a % mod;
  return c;
}
int p[N], v[N], mu[N], cnt = 0;
inline void sieve(int n) {
  mu[1] = 1;
  for (register int i = 2; i <= n; ++i) {
    if (!v[i]) p[++cnt] = i, mu[i] = mod - 1;
    for (register int j = 1; j <= cnt && i * p[j] <= n; ++j) {
      v[i * p[j]] = 1;
      if (i % p[j])
        mu[i * p[j]] = mod - mu[i];
      else
        break;
    }
  }
}
int b[N], pw[N];
int main() {
  sieve(2e6);
  int n = read(), k = read();
  for (register int i = 1; i <= k; ++i) pw[i] = qpow(i, n);
  for (register int i = 1; i <= k; ++i)
    for (register int j = i; j <= k; j += i)
      b[j] = (b[j] + 1ll * mu[i] * (pw[j / i] - pw[j / i - 1] + mod)) % mod;
  for (register int i = 1; i <= k; ++i) b[i] = (b[i] + b[i - 1]) % mod;
  int ans = 0;
  for (register int i = 1; i <= k; ++i) ans = (ans + (b[i] ^ i)) % mod;
  printf("%d\n", ans);
  return 0;
}
