#include <bits/stdc++.h>
using namespace std;
const int MAXN = 605;
const int MAXM = 100005;
int tot = 0, n, m, mod, a[MAXN][MAXN], d1[MAXN], d2[MAXN], fst[MAXN], pre[MAXM],
    b[MAXM], N = 0, c[MAXN << 1], q[MAXN], dp[MAXN];
int get() {
  int f = 0, v = 0;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') break;
  if (ch == '-')
    f = 1;
  else
    v = ch - 48;
  while (isdigit(ch = getchar())) v = v * 10 + ch - 48;
  if (f == 1) return -v;
  return v;
}
void add(int x, int y) {
  pre[++tot] = fst[x];
  fst[x] = tot;
  b[tot] = y;
}
int Pow(int a, int b) {
  int t = 1;
  for (; b > 0; b /= 2, a = (long long)a * a % mod)
    if (b & 1) t = (long long)t * a % mod;
  return t;
}
int det() {
  int res, flag = 0, tmp = 1;
  for (int i = 1; i <= N; i++) {
    if (!a[i][i]) {
      for (int j = i + 1; j <= N; j++)
        if (a[j][i]) {
          for (int k = i; k <= N; k++) swap(a[j][k], a[i][k]);
          flag ^= 1;
          break;
        }
    }
    if (!a[i][i]) return 0;
    for (int j = i + 1; j <= N; j++)
      if (a[j][i]) {
        tmp = (long long)tmp * a[i][i] % mod;
        int t = a[j][i];
        for (int k = i; k <= N; k++) {
          a[j][k] =
              ((long long)a[j][k] * a[i][i] - (long long)a[i][k] * t) % mod;
          if (a[j][k] < 0) a[j][k] += mod;
        }
      }
  }
  res = Pow(tmp, mod - 2);
  for (int i = 1; i <= N; i++) res = (long long)res * a[i][i] % mod;
  if (flag) return mod - res;
  return res;
}
int main() {
  n = get(), m = get(), mod = get();
  int x, y;
  for (int i = 1; i <= m; i++)
    x = get(), y = get(), add(x, y), d2[x]++, d1[y]++;
  int f = 1, r = 1;
  for (int i = 1; i <= n; i++)
    if (!d1[i]) c[++N] = i, q[r++] = i;
  for (int i = 1; i <= n; i++)
    if (!d2[i]) c[++N] = i;
  N >>= 1;
  for (; f != r; f++)
    for (int i = fst[q[f]]; i; i = pre[i])
      if (!(--d1[b[i]])) q[r++] = b[i];
  for (int i = 1; i <= N; i++) {
    memset(dp, 0, sizeof(dp));
    dp[c[i]] = 1;
    for (int j = 1; j <= r - 1; j++)
      if (dp[q[j]]) {
        for (int k = fst[q[j]]; k; k = pre[k]) {
          dp[b[k]] += dp[q[j]];
          if (dp[b[k]] >= mod) dp[b[k]] -= mod;
        }
      }
    for (int j = 1; j <= N; j++) a[i][j] = dp[c[j + N]];
  }
  printf("%d\n", det());
  return 0;
}
