#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
const int N = 4e6 + 10;
int f[N], h[N], sum[N];
int main() {
  int n = read(), mod = read();
  h[1] = 1, h[2] = mod - 1;
  int s = 0;
  for (int i = 1; i <= n; i++) {
    s = (s + h[i]) % mod, f[i] = (s + sum[i - 1]) % mod;
    for (int j = 2; j * i <= n; j++) {
      h[i * j] += f[i], h[i * j] %= mod;
      if ((i + 1) * j <= n)
        h[(i + 1) * j] -= f[i], h[(i + 1) * j] = (h[(i + 1) * j] + mod) % mod;
    }
    sum[i] = (sum[i - 1] + f[i]) % mod;
  }
  printf("%d", f[n]);
}
