#include <bits/stdc++.h>
using namespace std;
const int N = 2000010;
const int mod = 1000000007;
int f[N], n, k, ans, s[N];
long long ksmul(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod, y >>= 1;
  }
  return ret;
}
int main() {
  int i, j, h;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; i++) {
    f[i] = ((long long)f[i] + ksmul(i, n) - ksmul(i - 1, n)) % mod;
    for (j = 2 * i; j <= k; j += i) (f[j] -= f[i]) %= mod;
    s[i] = ((s[i - 1] + f[i]) % mod + mod) % mod;
    (ans += s[i] ^ i) %= mod;
  }
  printf("%d", ans);
  return 0;
}
