#include <bits/stdc++.h>
using namespace std;
long long dp[4000005], g[4000005], f[4000005];
signed main() {
  long long n, mod;
  scanf("%lld %lld", &n, &mod);
  dp[1] = 1;
  g[1] = 1;
  for (long long i = 2; i <= n; i++) {
    f[i] += f[i - 1] + 1;
    dp[i] = (dp[i] + g[i - 1] + f[i]) % mod;
    for (long long j = 2 * i; j <= n; j += i)
      f[j] = (f[j] + dp[i] - dp[i - 1]) % mod;
    g[i] = g[i - 1] + dp[i];
  }
  printf("%lld", (dp[n] + mod) % mod);
}
