#include <bits/stdc++.h>
using namespace std;
const long long N = 5e6 + 7;
long long n;
long long mod;
long long dak[N];
long long dp[N];
long long s[N];
signed main() {
  cin >> n >> mod;
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    dak[1 * i]++;
    dak[1 * i] %= mod;
    if (2 * i > n) continue;
    dak[2 * i]--;
    dak[2 * i] = (dak[2 * i] + mod) % mod;
  }
  s[1] = 1;
  for (long long i = 2; i <= n; i++) {
    dak[i] += dak[i - 1];
    dak[i] %= mod;
    dp[i] = s[i - 1] + dak[i];
    dp[i] %= mod;
    for (long long j = 2; j <= n / i; j++) {
      dak[i * j] += dp[i];
      dak[i * j] %= mod;
      if ((i + 1) * j > n) continue;
      dak[(i + 1) * j] -= dp[i];
      dak[(i + 1) * j] = (dak[(i + 1) * j] + mod) % mod;
    }
    s[i] = s[i - 1] + dp[i];
    s[i] %= mod;
  }
  cout << dp[n];
}
