#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int exp(long long int x, long long int y) {
  long long int ret = 1;
  for (; y; y >>= 1, x = (x * x) % mod) {
    if (y & 1) ret = (ret * x) % mod;
  }
  return ret;
}
long long int gcd(long long int x, long long int y) {
  return x % y == 0 ? y : gcd(y, x % y);
}
long long int lcm(long long int x, long long int y) {
  return x * (y / gcd(x, y));
}
long long int bsum(long long int u, long long int b) {
  return u < b ? u : bsum(u / b, b) + u % b;
}
long long int prival(long long int u, long long int p) {
  int cn = 0;
  while (u % p == 0) {
    cn++;
    u = u / p;
  }
  return cn;
}
bool isprime(long long int x) {
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
void YAY(void) { cout << "YES" << endl; }
void NAY(void) { cout << "NO" << endl; }
long long int dp[2100000], ex[2100000], ad[2100000], ans;
int n, k;
void prepr(void) {
  int i;
  for (i = 1; i <= k; i++) {
    ex[i] = exp(i, n);
  }
}
int main(void) {
  cin >> n >> k;
  int i, j, cc;
  long long int add;
  prepr();
  for (i = 1; i <= k; i++) {
    if (i == 1) {
      ad[1] = 1;
      dp[1] = 1;
      for (j = 2; i * j <= k; j++) {
        ad[i * j] -= ad[i];
        if (ad[i * j] < 0) ad[i * j] += mod;
        if (ad[i * j] > mod) ad[i * j] -= mod;
      }
      continue;
    }
    dp[i] = dp[i - 1];
    ad[i] += ex[i] - ex[i - 1];
    if (ad[i] > mod) ad[i] -= mod;
    if (ad[i] < 0) ad[i] += mod;
    for (j = 2; i * j <= k; j++) {
      ad[i * j] -= ad[i];
      if (ad[i * j] < 0) ad[i * j] += mod;
      if (ad[i * j] > mod) ad[i * j] -= mod;
    }
    dp[i] += ad[i];
    if (dp[i] > mod) dp[i] -= mod;
    if (dp[i] < 0) dp[i] += mod;
  }
  for (i = 1; i <= k; i++) {
    ans += (dp[i] ^ i);
    if (ans >= mod) ans -= mod;
  }
  cout << ans;
  return 0;
}
