#include <bits/stdc++.h>
using namespace std;
int p[1000000];
int c[1000000];
int get(int v0) {
  int v = v0;
  while (p[v] != v) v = p[v];
  while (v0 != v) {
    int v1 = p[v0];
    p[v0] = v;
    v0 = v1;
  }
  return v;
}
int main() {
  int N, K, M;
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++) {
    p[i] = i;
    c[i] = 1;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (get(a) == get(b)) continue;
    if (c[p[a]] > c[p[b]]) {
      c[p[a]] += c[p[b]];
      p[p[b]] = p[a];
    } else {
      c[p[b]] += c[p[a]];
      p[p[a]] = p[b];
    }
  }
  int cnt2 = 0;
  int cnt1 = 0;
  int total_pow = 0;
  for (int i = 0; i < N; i++)
    if (p[i] == i) {
      if (c[i] == 1)
        cnt1++;
      else {
        cnt2++;
        total_pow += min(K, c[i]);
      }
    }
  if (K == 1) {
    cout << max(0, cnt1 + cnt2 - 2) << endl;
  } else {
    int l = total_pow - 2 * (cnt2 - 1);
    if (cnt1 <= l)
      cout << 0 << endl;
    else {
      int q = (cnt1 - l + 3) / 2;
      cout << q - 1 << endl;
    }
  }
  return 0;
}
