#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int prime[maxn], mu[maxn], len;
long long p[maxn];
int vis[maxn];
void init() {
  mu[1] = 1;
  for (int i = 2; i < maxn; i++) {
    if (!vis[i]) {
      prime[++len] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= len && i * prime[j] < maxn; j++) {
      vis[i * prime[j]] = 1;
      if (i % prime[j]) {
        mu[i * prime[j]] = -mu[i];
      } else {
        mu[i * prime[j]] = 0;
        break;
      }
    }
  }
}
long long pow1(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = r * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return r;
}
vector<int> G[maxn];
int main() {
  init();
  memset(vis, 0, sizeof(vis));
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i < maxn; i++) p[i] = pow1(i, n);
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= k; j += i) G[j].push_back(i);
  }
  long long tmp = 0, ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = G[i].size() - 1; j >= 0; j--) {
      int v = G[i][j];
      tmp -= mu[v] * p[i / v - 1];
      tmp += mu[v] * p[i / v];
    }
    tmp = (tmp % mod + mod) % mod;
    ans += (tmp ^ i);
    ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
