#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
const int N = 4e6 + 10;
int n, p;
int f[N], pre[N];
int c[N];
void calc(int u) {
  for (int i = 2; i * u <= n; ++i) {
    c[i * u] = (c[i * u] + f[u] >= p ? c[i * u] + f[u] - p : c[i * u] + f[u]);
    c[std::min(i * (u + 1) - 1, n) + 1] =
        (c[std::min(i * (u + 1) - 1, n) + 1] + p - f[u] >= p
             ? c[std::min(i * (u + 1) - 1, n) + 1] + p - f[u] - p
             : c[std::min(i * (u + 1) - 1, n) + 1] + p - f[u]);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin >> n >> p;
  f[1] = 1;
  pre[1] = 1;
  for (int i = (2); i <= (n); ++i) {
    calc(i - 1);
    c[i] = (c[i] + c[i - 1] >= p ? c[i] + c[i - 1] - p : c[i] + c[i - 1]);
    f[i] = (c[i] + pre[i - 1]) % p;
    pre[i] = pre[i - 1];
    pre[i] = (pre[i] + f[i] >= p ? pre[i] + f[i] - p : pre[i] + f[i]);
  }
  cout << (f[n] + p) % p << endl;
  return 0;
}
