#include <bits/stdc++.h>
using namespace std;
long long f[4000006], mus[4000006];
int n, m;
int main() {
  cin >> n >> m;
  f[n] = mus[n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    f[i] = mus[i + 1];
    for (int k = 2; i * k <= n; ++k)
      f[i] =
          (f[i] + ((mus[i * k] - mus[min(i * k + k - 1, n) + 1]) % m + m) % m) %
          m;
    mus[i] = (mus[i + 1] + f[i]) % m;
  }
  cout << f[1];
  return 0;
}
