#include <bits/stdc++.h>
using namespace std;
struct point {
  int x;
  int ma;
  int sum;
};
bool operator<(const point& x, const point& y) {
  if (x.ma < y.ma) return true;
  if (x.ma > y.ma)
    return false;
  else
    return x.sum > y.sum;
}
const int N = (4 * 1e6) + 5;
int mod = 1e9 + 7;
int INF = 1e9 + 7;
long long a[N] = {0};
int main() {
  int T, n, o, y, l, r, p1, m, k, p = 0, x1, x2, k2, x;
  int ans = 0;
  point poi;
  cin >> n >> mod;
  a[1] = 1;
  for (int i = 2; i <= n; i++) {
    a[i] += a[i - 1] * 2;
    if (i > 2) a[i]++;
    for (int j = 2; j * i <= n; j++) {
      a[j * i] += a[i];
      a[j * i] -= a[i - 1];
      a[j * i] %= mod;
    }
    a[i] %= mod;
  }
  cout << a[n];
}
