#include <bits/stdc++.h>
using namespace std;
const int N = 2000002;
int n, k;
long long dp[N];
long long power(long long b, long long p) {
  if (!p) return 1;
  long long ret = power(b, p >> 1);
  return ret * ret % 1000000007 * (p & 1 ? b : 1) % 1000000007;
}
int main() {
  scanf("%d%d", &n, &k);
  long long ans = 0, sum = 0;
  for (int(i) = (1); (i) <= (int)(k); (i)++) {
    dp[i] = (dp[i] + power(i, n) - power(i - 1, n) + 1000000007) % 1000000007;
    sum = (dp[i] + sum) % 1000000007;
    ans = (ans + (sum ^ i)) % 1000000007;
    for (int j = 2 * i; j < N; j += i)
      dp[j] = (dp[j] - dp[i] + 1000000007) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
