#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e6 + 10;
long long f[maxn];
int mod = 998244353;
long long g[maxn];
int main() {
  f[1] = 1, f[2] = 2;
  int n;
  cin >> n >> mod;
  for (int i = 2; i <= n; i++) {
    if (i != 2) f[i] = (f[i - 1] * 2 % mod + 1 + g[i]) % mod;
    for (int j = 2; i * j <= n; j++) {
      g[i * j] = (g[i * j] + f[i] - f[i - 1] + mod) % mod;
    }
  }
  cout << f[n] << '\n';
}
