#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long inf = 0xc0c0c0c0c0c0c0c0;
const long long MAXN = 2e6 + 7;
long long mod = 1e9 + 7;
long long QPow(long long base, long long p) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * base % mod;
    p >>= 1;
    base = base * base % mod;
  }
  return ans;
}
bool check[MAXN];
long long prime[MAXN];
int mu[MAXN];
void Moblus() {
  memset(check, false, sizeof(check));
  mu[1] = 1;
  long long tot = 0;
  for (long long i = 2; i <= MAXN; i++) {
    if (!check[i]) {
      prime[tot++] = i;
      mu[i] = -1;
    }
    for (long long j = 0; j < tot; j++) {
      if (i * prime[j] > MAXN) break;
      check[i * prime[j]] = true;
      if (i % prime[j] == 0) {
        mu[i * prime[j]] = 0;
        break;
      } else {
        mu[i * prime[j]] = -mu[i];
      }
    }
  }
}
long long tool[MAXN];
long long tool2[MAXN];
int main() {
  Moblus();
  long long N, K;
  cin >> N >> K;
  memset(tool, 0, sizeof(tool));
  long long i, j;
  for (i = 0; i < MAXN; i++) tool2[i] = QPow(i, N);
  for (i = 1; i <= K; i++) {
    for (j = i; j <= K; j += i) {
      long long temp = mu[i] * (tool2[j / i] - tool2[j / i - 1]);
      tool[j] = (tool[j] + mod + temp) % mod;
    }
  }
  long long ans = 0;
  for (i = 1; i <= K; i++) {
    tool[i] = (tool[i] + tool[i - 1]) % mod;
    long long temp = tool[i] ^ i;
    ans = (ans + temp) % mod;
  }
  cout << ans;
  return 0;
}
