#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m, p;
vector<int> v, w;
int u[300][300];
vector<int> g[600];
int cp[600], cq[600];
int res[600][600];
int was[600][600];
int power(int a, int b) {
  int c = 1;
  while (b) {
    if (b & 1) c = ((long long)c * a) % p;
    b /= 2;
    a = ((long long)a * a) % p;
  }
  return c;
}
int go(int x, int z) {
  if (x == z) return 1;
  if (was[x][z]) return res[x][z];
  was[x][z] = 1;
  long long cur = 0;
  for (int i = 0; i < ((int)(g[x]).size()); i++) cur += go(g[x][i], z);
  return res[x][z] = cur % p;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    cp[a]++;
    cq[b]++;
    g[a].push_back(b);
  }
  int res = 1;
  for (int i = 0; i < n; i++)
    if (cq[i] == 0 && cp[i] == 0) {
      if ((((int)(v).size()) ^ ((int)(w).size())) & 1) res = p - res;
    } else if (cq[i] == 0)
      v.push_back(i);
    else if (cp[i] == 0)
      w.push_back(i);
  m = ((int)(v).size());
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) u[i][j] = go(v[i], w[j]);
  for (int i = 0; i < m; i++) {
    for (int j = i; j < m; j++)
      if (u[j][i] != 0) {
        for (int k = i; k < m; k++) swap(u[i][k], u[j][k]);
        if (i != j) res = (p - res) % p;
        break;
      }
    res = ((long long)res * u[i][i]) % p;
    if (!u[i][i]) break;
    for (int j = i + 1; j < m; j++)
      if (u[j][i]) {
        int tmp = ((long long)u[j][i] * power(u[i][i], p - 2)) % p;
        for (int k = i; k < m; k++)
          u[j][k] = (u[j][k] - ((long long)u[i][k] * tmp) % p + p) % p;
      }
  }
  printf("%d\n", res);
  return 0;
}
