#include <bits/stdc++.h>
using namespace std;
int miu[2000005];
bool p[2000005];
int pows[2000005];
const int modo = 1000000007;
int power(int x, int y) {
  if (y == 0) return 1;
  int t = power(x, y / 2);
  t = (long long)t * t % modo;
  if (y % 2 == 1) t = (long long)t * x % modo;
  return t;
}
int ans1[2000005];
int main() {
  int i;
  miu[1] = 1;
  for (i = 2; i <= 2000000; i++) {
    miu[i] = 1;
  }
  for (i = 2; i <= 2000000; i++) {
    if (!p[i]) {
      int j;
      for (j = i; j <= 2000000; j += i) {
        p[j] = true;
        miu[j] *= -1;
        if ((j / i) % i == 0) miu[j] = 0;
      }
    }
  }
  int n, k;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; i++) {
    pows[i] = power(i, n);
  }
  int j;
  for (j = 1; j <= k; j++) {
    if (miu[j] == 0) continue;
    int i;
    for (i = j; i <= k; i += j) {
      ans1[i] = (ans1[i] + miu[j] * (pows[i / j] - pows[i / j - 1])) % modo;
    }
  }
  int tot_ans = 0;
  for (i = 1; i <= k; i++) {
    ans1[i] = ((ans1[i - 1] + ans1[i]) % modo + modo) % modo;
    tot_ans = (tot_ans + (ans1[i] ^ i)) % modo;
  }
  printf("%d\n", tot_ans);
  return 0;
}
