#include <bits/stdc++.h>
using namespace std;
const int N = 605;
long long f[N][N], dp[N][N];
int in[N], out[N];
vector<int> g[N];
queue<int> q;
int s1[N], s2[N];
int c1, c2;
inline void swap(long long &x, int &y) {
  long long t = x;
  x = y;
  y = t;
  return;
}
int main() {
  int n, m, p;
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in[y]++;
    out[x]++;
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (!in[i]) {
      c1++;
      s1[c1] = i;
    }
    if (!out[i]) {
      c2++;
      s2[c2] = i;
    }
  }
  for (int i = 1; i <= c1; i++) {
    dp[s1[i]][s1[i]] = 1;
    q.push(s1[i]);
  }
  while (!q.empty()) {
    long long t = q.front();
    q.pop();
    for (int i = 0; i < g[t].size(); i++) {
      int y = g[t][i];
      if (!--in[g[t][i]]) q.push(y);
      for (int j = 1; j <= c1; j++)
        dp[s1[j]][y] = (dp[s1[j]][y] + dp[s1[j]][t]) % p;
    }
  }
  for (int i = 1; i <= c1; i++)
    for (int j = 1; j <= c2; j++) f[i][j] = dp[s1[i]][s2[j]];
  long long ans = 1;
  for (int i = 1; i <= c1; i++) {
    for (int j = i + 1; j <= c2; j++) {
      while (f[j][i]) {
        int t = f[i][i] / f[j][i];
        for (int k = i; k <= c1; k++) f[i][k] = (f[i][k] - t * f[j][k]) % p;
        for (int k = i; k <= c1; k++) swap(f[i][k], f[j][k]);
        ans *= -1;
      }
    }
    ans = ans * f[i][i] % p;
  }
  printf("%d\n", (ans + p) % p);
  return 0;
}
