// Задача "MP3-плеер"
// 4-я Интернет-олимпиада сезона 2009-2010, базовый уровень
// Автор задачи: Маским Носенко, nosenkomax@gmail.com
// Автор решения: Маским Носенко, nosenkomax@gmail.com

import java.util.*;
import java.io.*;

public class mp3_mn_TL implements Runnable {

	public static void main(String args[]) {
		new Thread(new mp3_mn_TL()).start();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	private String FNAME = "mp3";
	boolean eof = false;

	@Override
	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			br.close();
			out.close();

		} catch (Exception e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	void My_Assert(boolean b, String s) {
		if (!b)
			throw new Error("Assertion " + s);
	}

	final int NMAX = 5000;
	final int MMAX = (int) 1e9;
	
	int[] a;
	boolean[] was;
	int n;
	int ans;

	private void solve() {
		n = nextInt();
		int m = nextInt();
		My_Assert(2 <= n && n <= NMAX, "n is out of range: " + n);
		My_Assert(2 <= m && m <= MMAX, "m is out of range: " + m);

		a = new int[n];
		was = new boolean[n];
		ans = 0;
		go(0);
		
		out.println(ans % m);
		
	}

	private void go(int i) {
		if (i == n) {
			ans++;
			return;
		}
		for (int j = 0; j < n; j++)
			if (!was[j] && (i == 0 || j != a[i-1] + 1)) {
				was[j] = true;
				a[i] = j;
				go(i + 1);
				was[j] = false;
			}
				
	}
}