#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[4000001];
void solve() {
  int n, m;
  cin >> n >> m;
  dp[1] = 1;
  for (int i = 2, v; i <= n; i++) {
    if (i == 2) {
      dp[i] = 2;
    } else {
      dp[i] += 1 + dp[i - 1] * 2;
      dp[i] %= m;
    }
    v = (dp[i] - dp[i - 1] + m) % m;
    for (int j = i << 1; j <= n; j += i) {
      dp[j] += v;
      dp[j] %= m;
    }
  }
  cout << dp[n];
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  solve();
  return 0;
}
