#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5000005;
long long n, m;
long long f[maxn];
int main() {
  scanf("%lld%lld", &n, &m);
  f[1] = 1;
  for (long long x = 2; x <= n; x++) {
    f[x] = (f[x] + 2 * f[x - 1]) % m;
    if (x > 2) f[x] = (f[x] + 1) % m;
    long long cur = (f[x] - f[x - 1] + m) % m;
    for (long long y = 2 * x; y <= n; y += x) f[y] = (f[y] + cur) % m;
  }
  printf("%lld\n", f[n]);
  return 0;
}
