#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int par[1000010], siz[1000010];
vector<int> v;
int t = 0;
inline int pare(int x) {
  if (x == par[x])
    return x;
  else
    return pare(par[x]);
}
inline void join(int x, int y) {
  x = pare(x), y = pare(y);
  if (x == y) return;
  if (siz[x] > siz[y]) swap(x, y);
  par[x] = y;
  siz[y] += siz[x];
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) par[i] = i, siz[i] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    join(x - 1, y - 1);
  }
  for (int i = 0; i < n; i++) {
    if (i == par[i]) {
      if (siz[i] == 1)
        t++;
      else
        v.push_back(min(siz[i], k));
    }
  }
  if (k == 1) {
    cout << max(0, (int)(v.size()) + t - 2);
    return 0;
  }
  int sum = 0;
  if (!v.size()) {
    sum = 1;
    t--;
  } else {
    for (int i = 0; i < v.size(); i++) sum += v[i];
    sum -= (v.size() - 1) * 2;
  }
  printf("%d", max(0, (t - sum + 1) / 2));
  return 0;
}
