#include <bits/stdc++.h>
const int MAXN = 1e6 + 19;
int fa[MAXN], size[MAXN];
int getf(int node) {
  return fa[node] == node ? node : fa[node] = getf(fa[node]);
}
int n, m, k;
int ans;
struct cmp {
  bool operator()(const int &a, const int &b) const {
    return size[a] > size[b];
  }
};
std::priority_queue<int, std::vector<int>, cmp> q;
int main() {
  std::scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; ++i) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    std::scanf("%d%d", &u, &v);
    if (getf(u) != getf(v)) {
      size[getf(v)] += size[getf(u)];
      size[getf(u)] = 0;
      fa[getf(u)] = getf(v);
    }
  }
  int deg = 0;
  long long cap = 0;
  for (int i = 1; i <= n; ++i)
    if (getf(i) == i) q.push(i), ++deg, cap += std::min(k, size[i]);
  while (cap < 2 * (deg - 1)) {
    --deg, ++ans;
    int a = q.top();
    q.pop();
    int b = q.top();
    q.pop();
    cap -= std::min(k, size[a]);
    cap -= std::min(k, size[b]);
    size[a] += size[b];
    cap += std::min(k, size[a]);
    q.push(a);
  }
  std::printf("%d\n", ans);
  return 0;
}
