#include <bits/stdc++.h>
using namespace std;
int n, m, mod, rd[605], cd[605], ds[605], h[605], cnt;
long long G[605][605], d[605];
int id1[605], id2[605], bel1[605], bel2[605], tot1, tot2;
struct Edge {
  int to, next;
} w[100005];
void add(int x, int y) {
  w[++cnt] = (Edge){y, h[x]};
  h[x] = cnt;
  rd[y]++;
  cd[x]++;
}
long long ksm(long long x, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}
void dp(int s) {
  queue<int> q;
  for (int i = 1; i <= n; i++) d[i] = 0, ds[i] = rd[i];
  for (int i = 1; i <= n; i++)
    if (!rd[i]) q.push(i);
  d[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = h[u]; i; i = w[i].next) {
      int to = w[i].to;
      d[to] = (d[to] + d[u]) % mod;
      if (!(--ds[to])) q.push(to);
    }
  }
  for (int i = 1; i <= tot2; i++) G[bel1[s]][i] = d[id2[i]];
}
void Solve(int n) {
  long long ret = 1;
  for (int now = 1; now <= n; now++) {
    int k = 0;
    for (int i = now; i <= n; i++)
      if (G[i][now]) {
        k = i;
        break;
      }
    if (k != now) swap(G[k], G[now]), ret = mod - ret;
    ret = ret * G[now][now] % mod;
    long long inv = ksm(G[now][now], mod - 2);
    for (int i = now + 1; i <= n; i++) {
      long long v = G[i][now] * inv % mod;
      for (int j = now; j <= n; j++)
        G[i][j] = (G[i][j] - G[now][j] * v % mod) % mod;
    }
  }
  ret = (ret % mod + mod) % mod;
  printf("%lld\n", ret);
}
int main() {
  scanf("%d%d%d", &n, &m, &mod);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  for (int i = 1; i <= n; i++)
    if (!rd[i]) id1[++tot1] = i, bel1[i] = tot1;
  for (int i = 1; i <= n; i++)
    if (!cd[i]) id2[++tot2] = i, bel2[i] = tot2;
  for (int i = 1; i <= tot1; i++) dp(id1[i]);
  Solve(tot1);
}
