#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
namespace _c {
const double pi = acos(-1.0);
namespace min {
const int i8 = -128;
const int i16 = -32768;
const int i = -2147483647 - 1;
const long long l = -9223372036854775807LL - 1;
}  // namespace min
namespace max {
const int i8 = 127;
const int i16 = 32767;
const int i = 2147483647;
const long long l = 9223372036854775807LL;
}  // namespace max
}  // namespace _c
namespace _f {
template <typename T>
inline const T gcd(T m, T n) {
  while (n != 0) {
    T t = m % n;
    m = n;
    n = t;
  }
  return m;
}
template <typename T>
inline const T max(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T>
inline const T min(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline const T abs(const T &a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T pow(T a, T b) {
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
template <typename T>
inline T pow(T a, T b, const T &mod) {
  a %= mod;
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % mod;
    }
    a = a * a % mod;
    b >>= 1;
  }
  return res % mod;
}
}  // namespace _f
namespace io {
template <typename T>
inline void read(T &t) {
  register T res = 0, neg = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar()) {
    if (c == '-') {
      neg = -1;
    }
  }
  for (; isdigit(c); c = getchar()) {
    res = res * 10 + c - '0';
  }
  t = res * neg;
}
inline int in() {
  register int T;
  read(T);
  return T;
}
inline long long in_ll() {
  register long long T;
  read(T);
  return T;
}
}  // namespace io
int n, m, cnt;
long long p;
long long a[605][605], dp[605];
vector<pair<int, long long>> adj[605];
map<pair<int, int>, long long> edges;
vector<int> order;
bool is_sink[605], is_source[605], vis[605];
int sink_id[605];
void dfs(int v) {
  vis[v] = 1;
  for (auto &to : adj[v]) {
    if (!vis[to.first]) {
      dfs(to.first);
    }
  }
  order.push_back(v);
}
long long get_inv(long long x) {
  long long ret = 1;
  for (int pow = p - 2; pow; pow >>= 1) {
    if (pow & 1) {
      ret = ret * x % p;
    }
    x = x * x % p;
  }
  return ret;
}
long long guass_detemination() {
  long long det = 1;
  for (int row = 0, sel; row < cnt; ++row) {
    for (sel = row; sel < cnt && a[sel][row] == 0; ++sel)
      ;
    if (sel == cnt) return 0;
    if (sel != row) {
      for (int i = row; i < cnt; ++i) {
        swap(a[row][i], a[sel][i]);
      }
      det = -det;
    }
    det = det * a[row][row] % p;
    long long inv = get_inv(a[row][row]);
    for (int i = row + 1; i < cnt; ++i)
      if (a[i][row]) {
        long long c = a[i][row] * inv % p;
        for (int j = row; j < cnt; ++j) {
          a[i][j] = (a[i][j] - a[row][j] * c % p) % p;
        }
      }
  }
  return (det % p + p) % p;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> p;
  memset(is_sink, 1, n + 1);
  memset(is_source, 1, n + 1);
  for (int i = 0, u, v; i < m; ++i) {
    cin >> u >> v;
    is_source[v] = 0;
    is_sink[u] = 0;
    pair<int, int> pii = {u, v};
    if (edges.count(pii)) {
      edges[pii]++;
    } else {
      edges[pii] = 1;
    }
  }
  for (auto &x : edges)
    adj[x.first.first].emplace_back(x.first.second, x.second);
  for (int i = 1; i <= n; ++i) {
    if (is_sink[i]) {
      sink_id[i] = cnt++;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  reverse(order.begin(), order.end());
  for (int i = 1, cnt = 0; i <= n; ++i)
    if (is_source[i]) {
      memset(dp, 0, (n + 1) * sizeof(long long));
      dp[i] = 1;
      for (auto &v : order) {
        for (auto &to : adj[v]) {
          dp[to.first] = (dp[to.first] + dp[v] * to.second % p) % p;
        }
        if (is_sink[v]) {
          a[cnt][sink_id[v]] = dp[v];
        }
      }
      cnt++;
    }
  cout << guass_detemination() << endl;
}
