#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const long long mod = 1e9 + 7;
long long dp[N];
long long Pow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = Pow(a, b / 2);
  res = res * res % mod;
  if (b & 1) res = res * a % mod;
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    dp[i] = (dp[i] + Pow(i, n) - Pow(i - 1, n)) % mod;
    for (long long j = 2; j * i <= k; j++)
      dp[j * i] = (dp[j * i] - dp[i]) % mod;
  }
  long long ans = 0;
  for (long long i = 1; i <= k; i++) {
    dp[i] = ((dp[i] + dp[i - 1]) % mod + mod) % mod;
    ans = (ans + (dp[i] ^ i)) % mod;
  }
  cout << ans;
  return 0;
}
