#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmin(T &x, const T &y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
bool chkmax(T &x, const T &y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
T read() {
  T x = 0, f = 1;
  char c = getchar_unlocked();
  while ((c < '0') || (c > '9')) {
    if (c == '-') f = -1;
    c = getchar_unlocked();
  }
  while ((c >= '0') && (c <= '9'))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar_unlocked();
  return x * f;
}
template <typename T>
void write(T x, char c) {
  static char t[25];
  static int tlen;
  t[tlen = 1] = c;
  if (x < 0) putchar_unlocked('-'), x = -x;
  do t[++tlen] = (x % 10) ^ 48;
  while (x /= 10);
  while (tlen) putchar_unlocked(t[tlen--]);
}
const int maxn = 2000005, mod = 1e9 + 7;
int n, m;
bool isprime[maxn];
int prime[maxn], tot, mu[maxn];
void init() {
  int n = 2000000;
  memset(isprime, 1, sizeof(isprime));
  mu[1] = 1;
  for (int i = (int)(2), iend = (int)(n); i <= iend; ++i) {
    if (isprime[i]) prime[++tot] = i, mu[i] = -1;
    for (int j = (int)(1), jend = (int)(tot); j <= jend; ++j) {
      if (i * prime[j] > n) break;
      isprime[i * prime[j]] = 0;
      if (i % prime[j]) {
        mu[i * prime[j]] = -mu[i];
      } else {
        mu[i * prime[j]] = 0;
        break;
      }
    }
  }
}
int ans[maxn], pw[maxn];
void add(int &x, const int &y) {
  x += y;
  if (x < 0) x += mod;
  if (x >= mod) x -= mod;
}
int ksm(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return res;
}
int main() {
  init();
  n = read<int>(), m = read<int>();
  for (int i = (int)(1), iend = (int)(m); i <= iend; ++i) pw[i] = ksm(i, n);
  for (int d = (int)(1), dend = (int)(m); d <= dend; ++d) {
    if (!mu[d]) continue;
    for (int j = (int)(1), jend = (int)(m / d); j <= jend; ++j)
      add(ans[d * j], mu[d] * (pw[j] - pw[j - 1]));
  }
  for (int i = (int)(1), iend = (int)(m); i <= iend; ++i)
    add(ans[i], ans[i - 1]);
  int Ans = 0;
  for (int i = (int)(1), iend = (int)(m); i <= iend; ++i) add(Ans, ans[i] ^ i);
  write(Ans, '\n');
  return 0;
}
