#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const double PI = acos(-1);
const int N = 4e6 + 10;
int d[N], ans[N], sum[N];
int MOD;
void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += MOD;
}
void solve() {
  int n;
  cin >> n >> MOD;
  ans[1] = 1;
  for (int i = 2; i <= n; i++) d[i] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    add(d[i], d[i - 1]);
    add(ans[i], (d[i] + sum[i - 1]) % MOD);
    for (int j = i + i; j <= n; j += i) {
      sub(d[j], ans[i - 1]);
      add(d[j], ans[i]);
    }
    sum[i] = (sum[i - 1] + ans[i]) % MOD;
  }
  cout << ans[n] << "\n";
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int tc = 1;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
