#include <bits/stdc++.h>
using namespace std;
const int N = 605, M = 1e5 + 5;
int n, m, mo, K, h[N], e[M], nxt[M], tot, g[N][N], a[N], b[N], D[N], f[N],
    In[N], de[N];
int quick(int x, int y) {
  if (!y) return 1;
  int s = quick(x, y >> 1);
  s = (long long)s * s % mo;
  if (y & 1) s = (long long)s * x % mo;
  return s;
}
int calc() {
  int sig = 1, ans = 1;
  for (int i, j, k = 1, Inv, t; k <= K; k++) {
    for (i = k; i <= K && !g[i][k]; i++)
      ;
    if (i > K) return 0;
    if (i > k) {
      sig = -sig;
      for (j = k; j <= K; j++) swap(g[k][j], g[i][j]);
    }
    Inv = mo - quick(g[k][k], mo - 2);
    for (i = k + 1; i <= K; i++) {
      t = (long long)Inv * g[i][k] % mo;
      for (j = k; j <= K; j++)
        g[i][j] = (g[i][j] + (long long)t * g[k][j]) % mo;
    }
  }
  for (int i = 1; i <= K; i++) ans = (long long)ans * g[i][i] % mo;
  if (sig == -1) ans = -ans;
  if (ans < 0) ans += mo;
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &mo);
  for (int i = 1, x; i <= m; i++) {
    scanf("%d%d", &x, &e[i]);
    nxt[i] = h[x];
    h[x] = i;
    In[e[i]]++;
  }
  for (int i = 1, j = 0; i <= n; i++) {
    if (!In[i]) a[++K] = i;
    if (!h[i]) b[++j] = i;
  }
  for (int I = 1; I <= K; I++) {
    tot = 0;
    memset(f, 0, sizeof(f));
    memcpy(de, In, sizeof(de));
    for (int i = 1; i <= K; i++) D[++tot] = a[i];
    f[a[I]] = 1;
    for (int i = 1, j, x; i <= tot; i++) {
      x = D[i];
      for (j = h[x]; j; j = nxt[j]) {
        de[e[j]]--;
        f[e[j]] = (f[e[j]] + f[x]) % mo;
        if (!de[e[j]]) D[++tot] = e[j];
      }
    }
    for (int i = 1; i <= K; i++) g[I][i] = f[b[i]];
  }
  printf("%d\n", calc());
  return 0;
}
