#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int p[N], r[N];
int find(int x) {
  if (x != p[x]) p[x] = find(p[x]);
  return p[x];
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
    r[i] = 1;
  }
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    u = find(u);
    v = find(v);
    if (u != v) {
      p[u] = v;
      r[v] += r[u];
    }
  }
  int c = 0, s = 0;
  for (int i = 1; i <= n; ++i)
    if (p[i] == i) {
      ++c;
      s += min(k, r[i]);
    }
  if (k == 1)
    printf("%d\n", max(0, c - 2));
  else
    printf("%d\n", max(0, (2 * (c - 1) - s + 1) / 2));
  return 0;
}
