#include <bits/stdc++.h>
using namespace std;
const int maxn = 650 + 5;
long long quickpow(long long m, long long n, long long k) {
  long long b = 1;
  while (n > 0) {
    if (n & 1) b = (b * m) % k;
    n = n >> 1;
    m = (m * m) % k;
  }
  return b;
}
int n, e, mod;
vector<int> E[maxn];
int in[maxn], out[maxn];
int f[maxn][maxn];
int m[maxn][maxn];
int q[maxn];
int S[maxn], T[maxn];
int k1 = 1, k2 = 1;
long long ans = 1;
void guess() {
  for (int i = 1; i < k1; i++) {
    if (m[i][i] == 0) {
      for (int j = i + 1; j < k1; j++) {
        if (m[j][i]) {
          for (int k = i; k < k1; k++) m[i][k] = (m[i][k] + m[j][k]) % mod;
          break;
        }
      }
      if (m[i][i] == 0) {
        puts("0");
        return;
      }
    }
    long long inv = quickpow(m[i][i], mod - 2, mod);
    for (int j = i + 1; j < k1; j++) {
      long long temp = m[j][i] * inv % mod;
      if (temp == 0) continue;
      for (int k = i; k < k1; k++) m[j][k] = (m[j][k] - m[i][k] * temp) % mod;
    }
  }
  for (int i = 1; i < k1; i++) ans = ans * m[i][i] % mod;
  if (ans < 0) ans += mod;
  cout << ans << endl;
}
int main() {
  scanf("%d%d%d", &n, &e, &mod);
  for (int i = 1; i <= e; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in[y]++, out[x]++;
    E[x].push_back(y);
  }
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) S[k1++] = i;
  for (int i = 1; i <= n; i++)
    if (out[i] == 0) T[k2++] = i;
  int l = 1, r = 1;
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) q[r++] = i;
  while (l < r) {
    int now = q[l++];
    for (int i = 0; i < E[now].size(); i++) {
      in[E[now][i]]--;
      if (in[E[now][i]] == 0) q[r++] = E[now][i];
    }
  }
  for (int i = 1; i < k1; i++) f[S[i]][S[i]] = 1;
  for (int i = 1; i <= n; i++) {
    int u = q[i];
    for (int j = 1; j < k1; j++) {
      int s = S[j];
      for (int k = 0; k < E[u].size(); k++)
        f[s][E[u][k]] = (f[s][E[u][k]] + f[s][u]) % mod;
    }
  }
  for (int i = 1; i < k1; i++)
    for (int j = 1; j < k1; j++) m[i][j] = f[S[i]][T[j]];
  guess();
}
