#include <bits/stdc++.h>
using namespace std;
int MOD;
const int N = 666;
int expomod(long long int a, long long int e) {
  long long int res = 1;
  while (e) {
    if (e & 1) res = res * a % MOD;
    e /= 2;
    a = a * a % MOD;
  }
  return res;
}
int inverse(int x) { return expomod(x, MOD - 2); }
void mult(int &x, int y) { x = (long long int)x * y % MOD; }
void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
int determinant(vector<vector<int> > a) {
  int n = ((int)(a).size());
  assert(((int)(a[0]).size()) == n);
  int det = 1;
  for (int i = 0; i < (int)(n); i++) {
    int k = i;
    for (int j = (int)(i + 1); j < ((int)n); j++)
      if (a[j][i]) {
        k = j;
        break;
      }
    if (!a[k][i]) return 0;
    swap(a[i], a[k]);
    if (i != k && det) det = MOD - det;
    mult(det, a[i][i]);
    int inv = inverse(a[i][i]);
    for (int j = (int)(i + 1); j < ((int)n); j++) mult(a[i][j], inv);
    for (int j = 0; j < (int)(n); j++)
      if (j != i && a[j][i])
        for (int k = (int)(i + 1); k < ((int)n); k++)
          sub(a[j][k], (long long int)a[i][k] * a[j][i] % MOD);
  }
  return det;
}
int n, adj[N][N], in[N], out[N];
int main() {
  int m;
  while (scanf("%d %d %d", &n, &m, &MOD) > 0) {
    memset(adj, 0, sizeof adj);
    memset(in, 0, sizeof in);
    memset(out, 0, sizeof out);
    while (m--) {
      int u, v;
      scanf("%d %d", &u, &v);
      u--;
      v--;
      adj[u][v]++;
      if (adj[u][v] >= MOD) adj[u][v] -= MOD;
      out[u]++;
      in[v]++;
    }
    vector<int> src, sink, rest;
    for (int u = 0; u < (int)(n); u++) {
      if (in[u] == 0) src.push_back(u);
      if (out[u] == 0) sink.push_back(u);
      if (in[u] == 0 && out[u] == 0) adj[u][u] = 1;
      if (in[u] && out[u]) rest.push_back(u);
    }
    assert(((int)(src).size()) == ((int)(sink).size()));
    vector<int> rows, cols;
    for (auto x : src) rows.push_back(x);
    for (auto x : sink) cols.push_back(x);
    for (auto x : rest) rows.push_back(x), cols.push_back(x);
    int k = ((int)(src).size()), s = ((int)(rest).size()), nn = k + s;
    vector<vector<int> > mat(nn, vector<int>(nn));
    for (int i = 0; i < (int)(nn); i++)
      for (int j = 0; j < (int)(nn); j++) mat[i][j] = adj[rows[i]][cols[j]];
    for (int i = 0; i < (int)(s); i++) mat[k + i][k + i] = MOD - 1;
    int res = determinant(mat);
    if (s & 1) res = -res;
    res %= MOD;
    if (res < 0) res += MOD;
    printf("%d\n", res);
  }
  return 0;
}
