#include <bits/stdc++.h>
using namespace std;
void test() {
  while (1) {
    getchar();
    for (int x = 2; x <= 30; x++) {
      for (int i = 2; i <= x; i++) printf("%3d", x / i);
      printf("\n");
    }
  }
}
const int N = 4e6 + 5;
int n, m, pre;
int f[N], g[N];
int main() {
  scanf("%d%d", &n, &m);
  f[1] = 1;
  pre = 1;
  for (int i = 2; i <= n; i++) {
    g[i] += 1;
    g[min(n + 1, i + i)] -= 1;
  }
  for (int i = 2; i <= n; i++) {
    g[i] = (g[i] + g[i - 1]) % m;
    f[i] = (pre + g[i]) % m;
    int line = 1;
    while (1) {
      if (1ll * (i - 1) * (line + 1) + line + 1 > n) break;
      g[i * (line + 1)] = (g[i * (line + 1)] + f[i]) % m;
      if (1ll * (i + 1) * (line + 1) <= n)
        g[(i + 1) * (line + 1)] =
            (1ll * g[(i + 1) * (line + 1)] - f[i] + m) % m;
      line++;
    }
    pre = (pre + f[i]) % m;
  }
  printf("%d\n", f[n]);
  return 0;
}
