#include <bits/stdc++.h>
using namespace std;
long long int power[2000005];
long long int calculate_power(long long int x, long long int y) {
  if (y == 0) {
    return 1LL;
  }
  if (y & 1) {
    return (x * calculate_power(x, y - 1)) % 1000000007;
  }
  long long int ans = calculate_power(x, y / 2);
  return (ans * ans) % 1000000007;
}
long long int ans[2000005];
long long int n, k;
int main() {
  scanf("%lld %lld", &n, &k);
  for (long long int i = 1; i <= k; i++) {
    power[i] = calculate_power(i, n);
  }
  long long int final_ans = 0, sum = 0;
  for (long long int i = 1; i <= k; i++) {
    ans[i] = (ans[i] + ((power[i] - power[i - 1] + 1000000007) % 1000000007)) %
             1000000007;
    sum = (sum + ans[i]) % 1000000007;
    final_ans = (final_ans + ((sum ^ i) % 1000000007)) % 1000000007;
    for (long long int j = i + i; j <= k; j += i) {
      ans[j] = (ans[j] - ans[i] + 1000000007) % 1000000007;
    }
  }
  printf("%lld\n", final_ans);
  return 0;
}
