#include <bits/stdc++.h>
using namespace std;
const int MN = 611;
int n, m;
long long p;
int in[MN], out[MN];
int cnt[MN][MN];
long long c[MN][MN];
vector<int> ke[MN], rev[MN];
long long power(long long x, int k) {
  if (k == 0) return 1;
  if (k == 1) return x % p;
  long long mid = power(x * x % p, k >> 1);
  if (k & 1)
    return mid * x % p;
  else
    return mid;
}
long long inverse(long long x) { return power(x, p - 2); }
int f[MN];
int dfs(int u) {
  if (f[u] >= 0) return f[u];
  f[u] = 0;
  for (int v : rev[u]) {
    f[u] = (f[u] + dfs(v)) % p;
  }
  return f[u];
}
int main() {
  ios ::sync_with_stdio(false);
  while (scanf("%d%d%d", &n, &m, &p) == 3) {
    for (int i = (1), _b = (n); i <= _b; i++) {
      in[i] = out[i] = 0;
      ke[i].clear();
      rev[i].clear();
    }
    memset(cnt, 0, sizeof cnt);
    for (int i = (1), _b = (m); i <= _b; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      out[u]++;
      in[v]++;
      ke[u].push_back(v);
      rev[v].push_back(u);
    }
    for (int i = (1), _b = (n); i <= _b; i++)
      if (in[i] == 0 && out[i]) {
        memset(f, -1, sizeof f);
        for (int j = (1), _b = (n); j <= _b; j++)
          if (in[j] == 0 && out[j])
            if (j == i)
              f[j] = 1;
            else
              f[j] = 0;
        for (int j = (1), _b = (n); j <= _b; j++)
          if (in[j] && out[j] == 0) cnt[i][j] = dfs(j);
      }
    int nSource = 0;
    for (int i = (1), _b = (n); i <= _b; i++)
      if (in[i] == 0 && out[i]) {
        ++nSource;
        int nSink = 0;
        for (int j = (1), _b = (n); j <= _b; j++)
          if (out[j] == 0 && in[j]) {
            c[nSource][++nSink] = cnt[i][j];
          }
      }
    int bad = 0;
    for (int i = (1), _b = (n); i <= _b; i++)
      if (in[i] == 0 && out[i] == 0) {
        int a = 0, b = 0;
        for (int source = (1), _b = (i - 1); source <= _b; source++)
          if (in[source] == 0 && out[source]) ++a;
        for (int sink = (1), _b = (i - 1); sink <= _b; sink++)
          if (in[sink] && out[sink] == 0) ++b;
        if (a % 2 != b % 2) ++bad;
      }
    bad %= 2;
    n = nSource;
    long long mult = 1;
    for (int j = (1), _b = (n); j <= _b; j++) {
      int chosen = j;
      for (int k = (j + 1), _b = (n); k <= _b; k++)
        if (c[k][j] > c[chosen][j]) chosen = k;
      if (chosen != j) {
        bad = 1 - bad;
        for (int k = (1), _b = (n); k <= _b; k++) swap(c[chosen][k], c[j][k]);
      }
      for (int i = (j + 1), _b = (n); i <= _b; i++) {
        long long mult_i = c[j][j], mult_j = c[i][j];
        mult = (mult * mult_i) % p;
        for (int k = (1), _b = (n); k <= _b; k++)
          c[i][k] = (c[i][k] * mult_i - c[j][k] * mult_j + p * p) % p;
      }
    }
    long long res = 1;
    for (int i = (1), _b = (n); i <= _b; i++) res = res * c[i][i] % p;
    if (bad) res = (p - res) % p;
    res = res * inverse(mult) % p;
    cout << res << endl;
  }
  return 0;
}
