#include <bits/stdc++.h>
using namespace std;
const int maxn = 605;
int adj[maxn][maxn];
int cnt[maxn][maxn];
int a[maxn][maxn];
int ind[maxn], outd[maxn];
int S[maxn], T[maxn];
int n, m, ret, MOD;
void init() {
  scanf("%d%d%d", &n, &m, &MOD);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    adj[u][v]++;
    ind[v]++;
    outd[u]++;
  }
}
int que[maxn];
inline void Add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
void work() {
  int s0 = 0, s1 = 0, head = 1, tail = 0;
  for (int i = 1; i <= n; i++) {
    if (!ind[i]) {
      S[s0++] = i;
      que[++tail] = i;
      cnt[i][i] = 1;
    }
    if (!outd[i]) T[s1++] = i;
  }
  while (head <= tail) {
    int u = que[head++];
    for (int v = 1; v <= n; v++)
      if (adj[u][v]) {
        for (int i = 0; i < s0; i++)
          Add(cnt[S[i]][v], (long long)cnt[S[i]][u] * adj[u][v] % MOD);
        ind[v] -= adj[u][v];
        if (!ind[v]) que[++tail] = v;
      }
  }
  for (int i = 0; i < s0; i++)
    for (int j = 0; j < s1; j++) a[i][j] = cnt[S[i]][T[j]];
  ret = 1;
  for (int i = 0; i < s0; i++) {
    for (int j = i + 1; j < s1; j++)
      while (a[j][i] != 0) {
        long long d = a[i][i] / a[j][i];
        for (int k = i; k < s0; k++) a[i][k] = (a[i][k] - a[j][k] * d) % MOD;
        for (int k = i; k < s0; k++) {
          int t = a[i][k];
          a[i][k] = a[j][k];
          a[j][k] = t;
        }
        ret = -ret;
      }
    ret = (long long)a[i][i] * ret % MOD;
  }
  ret %= MOD;
  if (ret < 0) ret += MOD;
}
void print() { printf("%d\n", ret); }
int main() {
  init();
  work();
  print();
  return 0;
}
