#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e6 + 5;
long long n, mod, dp[MAXN], ddp[MAXN], sum[MAXN];
int main() {
  cin >> n >> mod;
  dp[1] = ddp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    dp[i] += (sum[i] + ddp[i - 1]);
    dp[i] %= mod;
    ddp[i] = (ddp[i - 1] + dp[i]) % mod;
    sum[i + 1] += sum[i];
    sum[i + 1] %= mod;
    for (long long j = 2; j * i <= n; j++) {
      sum[j * i] += dp[i];
      sum[j * i] %= mod;
      (sum[min(j * i + j, n + 1)] += (mod - dp[i])) %= mod;
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
