#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, j, x, t, y, k, n, m, z;
  cin >> n >> m;
  vector<int> dp(n + 1), sum(n + 1), diff(n + 1);
  sum[0] = diff[0] = 0;
  diff[1] = 1;
  diff[2] = -1;
  for (i = 1; i <= n; i++) {
    diff[i] = (diff[i] + diff[i - 1]) % m;
    dp[i] = (sum[i - 1] + diff[i]) % m;
    for (j = 2; i * j <= n; j++) {
      diff[i * j] = (diff[i * j] + dp[i]) % m;
      if ((i + 1) * j <= n)
        diff[(i + 1) * j] = (diff[(i + 1) * j] - dp[i] + m) % m;
    }
    sum[i] = (sum[i - 1] + dp[i]) % m;
  }
  cout << dp[n] << "\n";
}
