#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 100, mod = 1e9 + 7;
int n, K;
int f[N], Ans, cf[N];
long long qpow(long long x, int y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod, y >>= 1;
  }
  return ret;
}
void Inc(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= K; ++i) {
    Inc(cf[i], cf[i - 1]);
    Inc(f[i], qpow(i, n) % mod), Inc(f[i], cf[i]);
    for (int j = 2; i * j <= K; ++j)
      Inc(cf[i * j], f[i - 1]), Inc(cf[i * j], mod - f[i]);
    Inc(Ans, f[i] ^ i);
  }
  printf("%d", Ans);
  return 0;
}
