#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int n, m, k;
int p[1000006];
int sz[1000006];
int up(int x) {
  if (p[x] != x) p[x] = up(p[x]);
  return p[x];
}
void join(int x, int y) {
  x = up(x);
  y = up(y);
  if (x == y) return;
  if (rand() & 1) {
    sz[y] += sz[x];
    sz[x] = 0;
    p[x] = y;
  } else {
    sz[x] += sz[y];
    sz[y] = 0;
    p[y] = x;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < int(n); i++) {
    p[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < int(m); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    join(u, v);
  }
  int cnt = 0;
  for (int i = 0; i < int(n); i++) {
    if (sz[i] > 0) {
      sz[cnt] = sz[i];
      cnt++;
    }
  }
  if (k == 1) {
    cout << max(0, cnt - 2) << endl;
    return 0;
  }
  int sum = 0;
  for (int i = 0; i < int(cnt); i++) {
    sz[i] = min(sz[i], k);
    sum += sz[i];
  }
  sum = sum / 2 + 1;
  cout << max(cnt - sum, 0) << endl;
  return 0;
}
