#include <bits/stdc++.h>
using namespace std;
const int N = 610;
long long a[N][N], ans;
struct nd {
  int ne, to;
} e[200100];
int ru[N], chu[N], vis[N], n, m, mod, he[N], tot = 0, cnt = 0, tor[N], toc[N],
                                             du[N], f[N], q[N];
void add(int x, int y) {
  e[++tot].ne = he[x];
  he[x] = tot;
  e[tot].to = y;
  du[y]++;
}
long long ksm(long long x, int y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}
void topsort() {
  int i, j, x, y, fp = 1, rp = 0;
  for (i = 1; i <= n; i++)
    if (!du[i]) q[++rp] = i;
  while (fp <= rp) {
    x = q[fp++];
    for (i = he[x]; i; i = e[i].ne) {
      y = e[i].to;
      du[y]--;
      if (!du[y]) q[++rp] = y;
    }
  }
}
void gsxy() {
  int i, j, k;
  long long inv = 1, tmp;
  for (i = 1; i < n; i++) {
    for (j = i; j <= n; j++)
      if (a[j][i]) break;
    if (j > n) continue;
    if (j != i) {
      inv = mod - inv;
      for (k = i; k <= n; k++) swap(a[i][k], a[j][k]);
    }
    for (j = i + 1; j <= n; j++) {
      inv = (inv * a[i][i]) % mod;
      tmp = a[j][i];
      for (k = i; k <= n; k++)
        a[j][k] = ((a[j][k] * a[i][i] - a[i][k] * tmp) % mod + mod) % mod;
    }
  }
  for (i = 1; i <= n; i++) ans = (ans * a[i][i]) % mod;
  ans = (ans * ksm(inv, mod - 2)) % mod;
}
int main() {
  int i, j, k, x, y;
  scanf("%d%d%d", &n, &m, &mod);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    ru[y]++;
    chu[x]++;
    add(x, y);
  }
  topsort();
  cnt = 0;
  for (i = 1; i <= n; i++)
    if (!ru[i]) tor[i] = ++cnt;
  cnt = 0;
  for (i = 1; i <= n; i++)
    if (!chu[i]) toc[i] = ++cnt;
  for (i = 1; i <= n; i++)
    if (!ru[i]) {
      for (j = 1; j <= n; j++) f[j] = 0;
      f[i] = 1;
      for (j = 1; j <= n; j++)
        for (k = he[q[j]]; k; k = e[k].ne)
          f[e[k].to] = (f[e[k].to] + f[q[j]]) % mod;
      for (j = 1; j <= n; j++)
        if (!chu[j]) a[tor[i]][toc[j]] = f[j];
    }
  n = cnt;
  ans = 1;
  gsxy();
  cout << ans << endl;
  return 0;
}
