#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void addp(long long &x, long long res) {
  x = (x + res) % mod;
  if (x < 0) x += mod;
}
void addm(long long &x, long long res) { x = (x * res) % mod; }
long long binpow(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) addm(ans, a);
    addm(a, a);
    n >>= 1ll;
  }
  return ans;
}
const int N = 3e6;
long long n, k;
long long ans, tmp;
long long dp[N], st[N];
signed main() {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) st[i] = binpow(i, n);
  for (int i = 1; i <= k; ++i) {
    long long &d = dp[i];
    addp(d, st[i] - st[i - 1]);
    addp(tmp, d);
    addp(ans, (tmp ^ i));
    for (int j = (i << 1); j <= k; j += i) dp[j] -= d;
  }
  cout << ans;
  return 0;
}
