#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5, mod = 1e9 + 7;
long long sum(long long a, long long b) {
  long long tmp = (a + b) % mod;
  tmp %= mod;
  while (tmp < 0) tmp += mod;
  return (tmp);
}
long long zrb(long long a, long long b) {
  long long tmp = (a * b) % mod;
  tmp %= mod;
  while (tmp < 0) tmp += mod;
  return (tmp);
}
long long pw(long long a, long long b) {
  if (!b) return (1LL);
  long long tmp = pw(a, b / 2);
  return (zrb(zrb(tmp, tmp), b & 1 ? a : 1LL));
}
long long ans, n, k, A[N];
int32_t main() {
  scanf("%I64d %I64d", &n, &k);
  for (long long i = 1; i <= k; i++) {
    A[i] = sum(A[i], sum(pw(i, n), -pw(i - 1, n)));
    for (long long j = i + i; j < N; j += i) A[j] = sum(A[j], -A[i]);
    A[i] = sum(A[i], A[i - 1]);
    ans = sum(ans, A[i] ^ i);
  }
  printf("%I64d", ans);
}
