#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long dp[300005];
void solve() {
  long long ans = 0;
  dp[0] = 1;
  for (long long i = 1; i < (n + 1); ++i) dp[i] = dp[i - 1] * i % m;
  for (long long i = 0; i < (n); ++i) {
    ans = ans + (dp[n - i] * dp[i + 1] % m) * (n - i);
    ans %= m;
  }
  cout << ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    cin >> n >> m;
    solve();
  }
}
