#include <bits/stdc++.h>
using namespace std;
const int N = 4e6 + 5;
long long int n, m, dp[N], suf[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  dp[n] = 1;
  suf[n] = 1;
  for (long long int i = n - 1; i >= 1; i--) {
    dp[i] += suf[i + 1];
    dp[i] %= 1000000007;
    for (long long int j = 2; j * i <= n; j++) {
      long long int r = j * i, l = min(j * (i + 1), n + 1);
      dp[i] += (suf[r] - suf[l]);
      dp[i] %= m;
    }
    suf[i] += dp[i] + suf[i + 1];
    suf[i] %= m;
  }
  cout << dp[1] << "\n";
  return 0;
}
