#include <bits/stdc++.h>
void Get(long long &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
struct E {
  int V, Next;
} Edge[100005];
int EdgeTop;
int Head[605];
void Add(int U, int V) {
  Edge[++EdgeTop] = (E){V, Head[U]};
  Head[U] = EdgeTop;
}
int N, M;
long long P;
int Out[605];
int In[605];
void Init() {
  Get(N);
  Get(M);
  Get(P);
  for (int i = 1, U, V; i <= M; i++) {
    Get(U);
    Get(V);
    Out[U]++;
    In[V]++;
    Add(U, V);
  }
}
bool S[605];
bool T[605];
int Q[605];
int L, R;
long long G[605][605];
int K;
int IDS[605];
int IDT[605];
long long A[305][305];
long long Pow(long long X, long long Y) {
  long long Ans = 1;
  for (; Y; Y >>= 1) {
    if (Y & 1) (Ans *= X) %= P;
    (X *= X) %= P;
  }
  return Ans;
}
long long Det(int N) {
  long long Ans = 1;
  for (int i = 1; i <= N; i++) {
    if (A[i][i] == 0) {
      int Choose = 0;
      for (int j = i + 1; j <= N; j++)
        if (A[j][i] != 0) {
          Choose = j;
          break;
        }
      if (Choose == 0) return 0;
      for (int k = i; k <= N; k++) std::swap(A[i][k], A[Choose][k]);
      (Ans = -Ans) %= P;
      if (Ans < 0) Ans += P;
    }
    long long Inv = Pow(A[i][i], P - 2);
    (Ans *= A[i][i]) %= P;
    for (int k = i; k <= N; k++) (A[i][k] *= Inv) %= P;
    for (int j = i + 1; j <= N; j++) {
      long long K = A[j][i];
      for (int k = i; k <= N; k++) {
        (A[j][k] -= A[i][k] * K) %= P;
        if (A[j][k] < 0) A[j][k] += P;
      }
    }
  }
  return Ans;
}
long long Ans;
void Work() {
  bool Neg = 0;
  L = 1;
  for (int i = 1, k = 0; i <= N; i++) {
    if (In[i] == 0 && Out[i] == 0) {
      Neg ^= ((k + K) & 1);
      continue;
    }
    if (In[i] == 0) {
      S[i] = 1;
      Q[++R] = i;
      In[i] = -1;
      K++;
      IDS[i] = K;
      G[K][i] = 1;
    }
    if (Out[i] == 0) {
      T[i] = 1;
      k++;
      IDT[i] = k;
    }
  }
  for (; L <= R; L++) {
    for (int i = Head[Q[L]]; i; i = Edge[i].Next) {
      In[Edge[i].V]--;
      if (In[Edge[i].V] == 0) {
        Q[++R] = Edge[i].V;
        In[Edge[i].V] = -1;
      }
    }
  }
  for (int k = 1, i; k <= N; k++) {
    i = Q[k];
    for (int j = Head[i]; j; j = Edge[j].Next) {
      int V = Edge[j].V;
      for (int p = 1; p <= K; p++) {
        (G[p][V] += G[p][i]) %= P;
      }
    }
  }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (S[i] == 1 && T[j] == 1) {
        A[IDS[i]][IDT[j]] = G[IDS[i]][j];
      }
  Ans = Det(K);
  if (Neg) {
    (Ans = -Ans) %= P;
    if (Ans < 0) Ans += P;
  }
}
void Debug() {
  P = 99999989;
  A[1][1] = 3;
  A[1][2] = 8;
  A[2][1] = 1;
  A[2][2] = 4;
  long long Ans = Det(2);
  printf("%I64d\n", Ans);
}
void Output() { printf("%I64d\n", Ans); }
int main() {
  Init();
  Work();
  Output();
  return 0;
}
