#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4000010;
long long f[MAXN], sum[MAXN], MOD;
int main() {
  int n;
  scanf("%d %lld", &n, &MOD);
  f[n] = 1;
  sum[n] = 1;
  for (int i = n - 1; i; --i) {
    f[i] = (f[i] + sum[i + 1]) % MOD;
    for (int j = 2; j * i <= n; ++j) {
      int l = j * i, r = min(n, i * j + j - 1);
      f[i] += sum[l] - sum[r + 1];
      f[i] = (f[i] % MOD + MOD) % MOD;
    }
    sum[i] = (sum[i + 1] + f[i]) % MOD;
  }
  printf("%lld\n", f[1]);
  return 0;
}
