#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
const int mod = 1e9 + 7;
int n, m;
int add[N];
int cnt[N];
int pw[N];
bool vis[N];
bool use[N];
int binPow(int x, int y) {
  if (!y) return 1;
  int val = binPow(x, y >> 1);
  val = 1LL * val * val % mod;
  if (y & 1) val = 1LL * val * x % mod;
  return val;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i < N; ++i) use[i] = 1;
  for (int i = 2; i < N; ++i) {
    if (vis[i]) continue;
    for (int j = i; j < N; j += i) {
      if (j % (1LL * i * i) == 0) use[j] = 0;
      vis[j] = 1, cnt[j]++;
    }
  }
  for (int i = 1; i < N; ++i) pw[i] = binPow(i, n);
  for (int i = 1; i < N; ++i) {
    if (!use[i]) continue;
    int tmp = (cnt[i] & 1) ? -1 : +1;
    for (int j = i; j < N; j += i) {
      add[j] += tmp * pw[j / i], add[j] %= mod, add[j] += mod, add[j] %= mod;
      if (j + i < N) {
        add[j + i] -= tmp * pw[j / i], add[j + i] %= mod, add[j + i] += mod,
            add[j + i] %= mod;
      }
    }
  }
  int cur = 0, res = 0;
  for (int i = 1; i <= m; ++i) {
    cur += add[i], cur %= mod;
    res += cur ^ i, res %= mod;
  }
  cout << res;
}
