#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<long long> dp(n + 1);
  dp[n] = 1;
  long long sum = 0;
  vector<long long> s(n + 2);
  for (int i = n; i >= 1; i--) {
    for (long long div = 2; div * i <= n; div++) {
      long long mn = i * div;
      long long mx = min(1LL * n, (i + 1) * div - 1);
      dp[i] = (dp[i] + s[mn] - s[mx + 1] + m) % m;
    }
    dp[i] = (dp[i] + sum + m) % m;
    sum = (sum + dp[i] + m) % m;
    s[i] = (dp[i] + s[i + 1] + m) % m;
  }
  cout << dp[1] << '\n';
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  solve();
}
