#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 7;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
const long long maxl = 20;
const long long SQ = 70;
long long pw(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
long long dp[maxn], add[maxn];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
  ;
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) dp[i] = pw(i, n);
  long long ans = 0;
  for (long long i = 1; i <= k; i++) {
    dp[i] = (dp[i] - add[i] + mod) % mod;
    add[i + 1] = (add[i + 1] + add[i] + mod) % mod;
    for (long long j = 2; j <= (k / i); j++) {
      add[j * i] = (add[j * i] + dp[i] + mod) % mod;
      if (j * (i + 1) <= k)
        add[j * (i + 1)] = (add[j * (i + 1)] - dp[i] + mod) % mod;
    }
    ans = (ans + (dp[i] ^ i) + mod) % mod;
  }
  cout << ans << "\n";
  return 0;
}
