#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
  long long x = 1 % m;
  a %= m;
  while (b) {
    if ((1 & b)) x = x * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return x;
}
int smpf[2000005];
void SMPF() {
  for (int i = 1; i < 2000005; i++) smpf[i] = i;
  for (int i = 2; i < 2000005; i += 2) smpf[i] = 2;
  for (int i = 3; i * i < 2000005; i += 2) {
    if (smpf[i] == i) {
      for (int j = i * i; j < 2000005; j += 2 * i) {
        if (smpf[j] == j) {
          smpf[j] = i;
        }
      }
    }
  }
}
int mobius[2000005];
void pre_mu() {
  memset(mobius, 0, sizeof(mobius));
  mobius[1] = 1;
  for (int i = 2; i < 2000005; i++) {
    if (smpf[i] != smpf[i / smpf[i]]) {
      mobius[i] = -mobius[i / smpf[i]];
    }
  }
}
long long delta[2000005];
long long ptab[2000005];
int main() {
  SMPF();
  pre_mu();
  memset(delta, 0, sizeof(delta));
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) ptab[i] = power(i, n, 1000000007);
  memset(delta, 0, sizeof(delta));
  for (int d = 1; d <= k; d++) {
    int now = 1;
    for (int j = d; j <= k; j += d) {
      long long prev = mobius[d] * ptab[now - 1];
      long long cur = mobius[d] * ptab[now];
      delta[j] += cur - prev;
      while (delta[j] >= 1000000007) delta[j] -= 1000000007;
      while (delta[j] < 0) delta[j] += 1000000007;
      now++;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    delta[i] += delta[i - 1];
    if (delta[i] >= 1000000007) delta[i] -= 1000000007;
    ans += delta[i] ^ i;
    while (ans >= 1000000007) ans -= 1000000007;
  }
  printf("%lld\n", ans);
}
