#include <bits/stdc++.h>
using namespace std;
void main0();
int main() {
  clock_t start, end;
  ios::sync_with_stdio(false);
  cin.tie(0);
  main0();
  return 0;
}
const int dx[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int dy[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int N = 4e6 + 5;
const int M = 1e5;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double Pi = acos(-1.0);
mt19937 rnd(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
int n, mod;
long long cnt[N], offset = 0;
long long suf[N];
long long dp[N];
long long pre[N];
void getmod(long long &x) {
  while (x >= mod) x -= mod;
}
void main0() {
  cin >> n >> mod;
  dp[1] = 1;
  for (int i = 1; i <= n; ++i) {
    if (i >= 2) {
      pre[i] += pre[i - 1];
      getmod(pre[i]);
      dp[i] = pre[i];
    }
    pre[i + 1] += dp[i];
    getmod(pre[i]);
    for (int j = 2; j <= n; ++j) {
      int l = i * j;
      if (l > n) break;
      int r = min(n, (i + 1) * j - 1);
      pre[l] += dp[i];
      getmod(pre[l]);
      pre[r + 1] += mod - dp[i];
      getmod(pre[r + 1]);
    }
  }
  cout << dp[n] << endl;
}
