#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pld = pair<ld, ld>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vld = vector<ld>;
using vs = vector<string>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpld = vector<pld>;
int n;
ll m;
ll dp[400010];
void solvetask() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) dp[i] = 0;
  dp[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    dp[i] = (dp[i] + 2 * dp[i + 1]) % m;
    for (int j = 2; j * i <= n; j++)
      dp[i] = (dp[i] + dp[j * i] - dp[j * i + j] + m) % m;
  }
  cout << (dp[1] - dp[2] + m) % m << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) solvetask();
}
