#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0, y = 1;
  while (c < '0' || c > '9') {
    if (c == '-') y = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * y;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline long long readll() {
  char c = getchar();
  long long x = 0;
  int y = 1;
  while (c < '0' || c > '9') {
    if (c == '-') y = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * y;
}
void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) writell(x / 10);
  putchar(x % 10 + '0');
}
int n;
long long mod, suf[4000005];
signed main() {
  int i, j;
  long long dp, s = 0;
  cin >> n >> mod;
  suf[n] = s = 1;
  for (i = n - 1; i; i--) {
    dp = s;
    for (j = 2; i * j <= n; j++)
      dp = (dp + suf[i * j] - suf[min(n + 1, i * j + j)]) % mod;
    s = (s + dp) % mod;
    suf[i] = (suf[i + 1] + dp) % mod;
  }
  cout << dp;
  return 0;
}
