#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int num;
  int next;
};
Edge e[100001];
int d1[601], d2[601], d3[601];
int e1[100001], e2[100001];
int h1[601], h2[601];
long long a[601][601];
long long d[601][601];
int p[601];
bool vis[601];
int s[601];
int n, m, z;
long long q;
void add(int u, int v) {
  z++;
  e[z].num = v;
  e[z].next = p[u];
  p[u] = z;
}
void gcd(long long a, long long b, long long &d, long long &x, long long &y) {
  if (a == 0) {
    y = 1;
    d = b;
    x = 0;
    return;
  }
  gcd(b % a, a, d, y, x);
  x -= (b / a) * y;
  return;
}
long long inv(long long k) {
  long long d, x, y;
  gcd(k, q, d, x, y);
  return (x + q) % q;
}
int main() {
  memset(p, -1, sizeof(p));
  scanf("%d%d%I64d", &n, &m, &q);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &e1[i], &e2[i]);
    d1[e1[i]]++;
    d2[e2[i]]++;
    d3[e2[i]]++;
    add(e1[i], e2[i]);
  }
  z = 0;
  for (int i = 1; i <= n; i++)
    if (d2[i] == 0) {
      z++;
      h1[i] = z;
      s[z] = i;
    }
  z = 0;
  for (int i = 1; i <= n; i++)
    if (d1[i] == 0) {
      z++;
      h2[i] = z;
    }
  for (int i = 1; i <= n; i++) d[i][i] = 1;
  while (s[z] > 0) {
    int u = s[z];
    z--;
    for (int temp = p[u]; temp != -1; temp = e[temp].next) {
      int v = e[temp].num;
      d2[v]--;
      if (d2[v] == 0) s[++z] = v;
      for (int j = 1; j <= n; j++) {
        d[j][v] += d[j][u];
        d[j][v] %= q;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (h1[i] != 0 && h2[j] != 0) a[h1[i]][h2[j]] = d[i][j];
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (d1[i] == 0) z++;
  for (int i = 1; i <= z; i++) {
    int k = i;
    for (int j = i + 1; j <= z; j++)
      if (a[j][i] > a[k][i]) k = j;
    if (k != i) {
      cnt++;
      for (int j = 1; j <= z; j++) swap(a[k][j], a[i][j]);
    }
    if (a[i][i] == 0) {
      printf("0\n");
      return 0;
    }
    for (k = i + 1; k <= z; k++)
      if (a[i][k] != 0) break;
    long long t;
    t = inv(a[i][i]);
    if (k > z) {
      for (int j = i + 1; j <= z; j++) a[j][i] = 0;
      continue;
    }
    for (int j = i + 1; j <= z; j++)
      for (k = z; k >= i; k--) {
        a[j][k] -= ((a[j][i] * t) % q) * a[i][k];
        a[j][k] %= q;
        a[j][k] += q;
        a[j][k] %= q;
      }
  }
  long long ans = 1;
  for (int i = 1; i <= z; i++) ans = (ans * a[i][i]) % q;
  ans %= q;
  if (cnt % 2 == 0)
    printf("%I64d\n", ans);
  else
    printf("%I64d\n", (q - ans) % q);
  return 0;
}
