#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
vector<char*> tokenizer(const char* args) {
  char* token = new char[111];
  strcpy(token, args);
  token = strtok(token, ", ");
  vector<char*> v({token});
  while (token = strtok(NULL, ", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back();
  debugg(args, T...);
}
const double PI = acos(-1);
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
tpo:
  while (test--) {
    long long n, mod;
    cin >> n >> mod;
    vector<long long> dp(n + 1, 0);
    vector<long long> prefix(n + 1, 0);
    long long prevSum = 0;
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        prevSum = 1;
        dp[i] = 1;
        prefix[i] = 1;
        continue;
      }
      prefix[i] += prefix[i - 1];
      dp[i] = (prefix[i] + prevSum) % mod;
      dp[i] += (i / 2);
      if (i % 2 == 1) dp[i] += 1;
      dp[i]--;
      dp[i] %= mod;
      for (int a = 2 * i, p = 2; a <= n; a += i, p += 1) {
        prefix[a] += dp[i];
        prefix[a] %= mod;
        int subIndex = a + p;
        if (subIndex <= n) {
          prefix[subIndex] -= dp[i];
          if (prefix[subIndex] < 0) {
            prefix[subIndex] = ((prefix[subIndex] % mod) + mod) % mod;
          }
        }
      }
      prevSum += dp[i];
      prevSum %= mod;
    }
    cout << dp[n] << "\n";
  }
  return 0;
}
