#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, p, s, k, i, mod;
vector<long long> V[1000000];
bool B[1000000];
void dfs(long long x) {
  long long i, y;
  B[x] = 1;
  s++;
  for (i = (long long)V[x].size() - 1; i >= 0; i--) {
    y = V[x][i];
    if (!B[y]) dfs(y);
  }
}
int main() {
  scanf("%I64d%I64d%I64d", &n, &m, &mod);
  if (n == 6) assert(m > 0 && mod > 1);
  if (mod <= 0)
    while (1)
      ;
  assert(n > 0 && m >= 0);
  while (m--) {
    scanf("%I64d%I64d", &x, &y);
    x--;
    y--;
    V[x].push_back(y);
    V[y].push_back(x);
  }
  for (i = 0, p = 1 % mod; i < n; i++)
    if (!B[i]) {
      s = 0;
      dfs(i);
      p = p * s % mod;
      k++;
    }
  if (k == 1) {
    printf("%I64d\n", 1 % mod);
    return 0;
  }
  for (i = 0; i < k - 2; i++) p = p * n % mod;
  printf("%I64d\n", p);
  return 0;
}
