#include <bits/stdc++.h>
const int N = 609;
long long ans = 1;
int f[N], n, ind[N], oud[N], son[N], ec, node1[N], node2[N], m, MOD;
long long a[N][N];
bool vis[N];
int lnk[100009], nxt[100009];
int dp(const int u) {
  if (vis[u]) return f[u];
  vis[u] = true;
  for (int i = son[u]; i; i = nxt[i]) f[u] = (f[u] + dp(lnk[i])) % MOD;
  return f[u];
}
void Gauss() {
  for (int i = 1, j; i <= m; ++i) {
    for (j = i; j <= m && !a[j][i]; ++j)
      ;
    if (j > m) return;
    if (i != j) {
      std::swap(a[i], a[j]);
      ans *= -1;
    }
    for (j = i + 1; j <= m; ++j)
      while (a[j][i]) {
        long long d = a[i][i] / a[j][i];
        for (int k = i; k <= m; ++k) {
          (a[i][k] -= d * a[j][k] % MOD) %= MOD;
          a[i][k] = (a[i][k] + MOD) % MOD;
        }
        std::swap(a[i], a[j]);
        ans *= -1;
      }
  }
}
inline void addedge(const int x, const int y) {
  ++ec;
  nxt[ec] = son[x];
  lnk[ec] = y;
  son[x] = ec;
}
int main() {
  scanf("%d%d%d", &n, &m, &MOD);
  for (int x, y; m--;) {
    scanf("%d%d", &x, &y);
    addedge(y, x);
    ++oud[x];
    ++ind[y];
  }
  m = 0;
  for (int i = 1; i <= n; ++i)
    if (!ind[i]) node1[++m] = i;
  m = 0;
  for (int i = 1; i <= n; ++i)
    if (!oud[i]) node2[++m] = i;
  for (int i = 1; i <= m; ++i) {
    memset(f, 0, sizeof f);
    memset(vis, 0, sizeof vis);
    f[node1[i]] = 1;
    for (int j = 1; j <= m; ++j) {
      a[i][j] = dp(node2[j]);
    }
  }
  Gauss();
  for (int i = 1; i <= m; ++i) (ans *= a[i][i]) %= MOD;
  printf("%I64d\n", (ans + MOD) % MOD);
}
