#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, next;
};
struct edge e[200010];
int n, m, num, mod, t, w, s1, s2, flag = 1, ans;
int head[610], q[610], f[610][610], c[610][610], in[610], out[610], a[610],
    b[610];
int fpow(int i, int j) {
  int ret = 1;
  while (j) {
    if (j & 1) ret = (long long)ret * i % mod;
    i = (long long)i * i % mod;
    j /= 2;
  }
  return ret;
}
void add(int u, int v) {
  e[num].u = u;
  e[num].v = v;
  e[num].next = head[u];
  head[u] = num;
  num++;
}
void work() {
  int i, j;
  while (t <= w) {
    j = head[q[t]];
    while (j != -1) {
      for (i = 1; i <= s1; i++)
        f[e[j].v][i] = (f[e[j].v][i] + f[q[t]][i]) % mod;
      out[e[j].v]--;
      if (!out[e[j].v]) {
        q[++w] = e[j].v;
        out[e[j].v] = 1;
      }
      j = e[j].next;
    }
    t++;
  }
}
void gauss() {
  int i, j, k, inv, p;
  for (i = 1; i <= s1; i++) {
    j = i;
    while (j <= s1 && c[j][i] % mod == 0) j++;
    if (j <= s1) {
      if (i != j) {
        swap(c[i], c[j]);
        flag = -flag;
      }
      inv = fpow(c[i][i], mod - 2);
      for (j = i + 1; j <= s1; j++) {
        p = (long long)inv * c[j][i] % mod;
        for (k = i; k <= s1; k++)
          c[j][k] = (c[j][k] - (long long)c[i][k] * p % mod) % mod;
      }
    }
  }
}
int main() {
  int i, j, x, y;
  scanf("%d%d%d", &n, &m, &mod);
  memset(head, -1, sizeof(head));
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    in[y]++;
    out[x]++;
    add(y, x);
  }
  for (i = 1; i <= n; i++) {
    if (!in[i] && out[i]) a[i] = ++s1;
    if (!out[i] && in[i]) b[i] = ++s2;
  }
  for (i = 1; i <= n; i++)
    if (!out[i]) {
      w++;
      q[w] = i;
      f[i][b[i]] = 1;
    }
  work();
  for (i = 1; i <= n; i++)
    if (a[i]) {
      for (j = 1; j <= s1; j++) c[a[i]][j] = f[i][j];
    }
  ans = 1;
  for (i = 1; i <= n; i++)
    if (!in[i] && !out[i]) {
      for (j = i + 1; j <= n; j++)
        if (a[j] || b[j]) ans = -ans;
    }
  gauss();
  for (i = 1; i <= s1; i++) ans = (long long)ans * c[i][i] % mod;
  printf("%d\n", (ans * flag + mod) % mod);
  return 0;
}
