#include <bits/stdc++.h>
using namespace std;
const int maxn = 610, maxm = 100010;
long long A[maxn][maxn];
long long f[maxn][maxn];
int deg[2][maxn];
int v[2][maxn];
void dfs(int);
struct edge {
  int to, nxt;
};
edge G[maxm];
int head[maxn], cnt;
long long p;
int n, c;
int main() {
  int m;
  scanf("%d %d %lld", &n, &m, &p);
  int a, b;
  while (m--) {
    scanf("%d %d", &a, &b);
    deg[0][b]++, deg[1][a]++;
    G[++cnt] = {b, head[a]}, head[a] = cnt;
  }
  int c0 = 0, c1 = 0;
  for (int i = 1; i <= n; i++) {
    if (!deg[0][i]) v[0][++c0] = i;
    if (!deg[1][i]) v[1][++c1] = i;
  }
  c = c1;
  for (int i = 1; i <= c; i++) dfs(v[0][i]);
  for (int i = 1; i <= c; i++)
    for (int j = 1; j <= c; j++) A[i][j] = f[v[0][i]][v[1][j]];
  int x, y;
  bool flag = false;
  long long ans = 1, tmp;
  for (int i = 1; i <= c; i++) {
    for (int j = i + 1; j <= c; j++) {
      x = i, y = j;
      while (A[y][i]) {
        tmp = A[x][i] / A[y][i];
        for (int k = i; k <= c; k++) A[x][k] = (A[x][k] - tmp * A[y][k]) % p;
        x ^= y ^= x ^= y;
      }
      if (x != i) {
        for (int k = i; k <= c; k++) A[i][k] ^= A[j][k] ^= A[i][k] ^= A[j][k];
        flag ^= 1;
      }
    }
    ans = ans * A[i][i] % p;
    if (!ans) break;
  }
  if (ans && flag) ans = -ans;
  printf("%lld\n", (ans + p) % p);
  return 0;
}
bool vis[maxn];
void dfs(const int u) {
  vis[u] = true;
  if (!deg[1][u]) {
    f[u][u] = 1;
    return;
  }
  for (int i = head[u]; i; i = G[i].nxt) {
    if (!vis[G[i].to]) dfs(G[i].to);
    for (int j = 1; j <= c; j++)
      f[u][v[1][j]] = f[u][v[1][j]] + f[G[i].to][v[1][j]];
  }
  for (int i = 1; i <= c; i++) f[u][v[1][i]] %= p;
  return;
}
