import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class mp3_sm {
	long m;
	private void solve() {
		int n = in.nextInt();
		assert 2 <= n && n <= 2000;
		m = in.nextLong();
		assert 2 <= m && m <= 1e9;
		long[][] c = new long[n + 1][n + 1];
		c[0][0] = 1;
		for (int i = 1; i <= n; i++) {
			c[i][0] = 1;
			for (int j = 1; j <= n; j++) {
				c[i][j] = (c[i - 1][j - 1] + c[i - 1][j])  % m;
			}
		}
		long sum = 0;
		for (int k = 0; k <= n; k++) {
			long r = (k % 2 == 0 ? 1 : -1) * c[n - 1][k] * fact(n - k);
			sum = ((sum + r) % m + m) % m;
		}
		out.println(sum);
	}

	private long fact(int i) {
		long res = 1;
		for (int j = 2; j <= i; j++) {
			res = (res * j) % m;
		}
		return res;
	}

	Scanner in;
	PrintWriter out;

	void run() {
		try {
			in = new Scanner(new File("mp3.in"));
			out = new PrintWriter("mp3.out");
			solve();
			out.close();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) {
		new mp3_sm().run();
	}

}
