#include <bits/stdc++.h>
using namespace std;
long long n, m, k, cc;
vector<long long> graph[1000100];
long long vis[1000100];
inline void dfs(long long src) {
  vis[src] = true;
  cc++;
  for (auto it : graph[src]) {
    if (!vis[it]) dfs(it);
  }
}
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  scanf("%lld", &k);
  for (long long i = 0; i < m; i++) {
    long long x, y;
    scanf("%lld", &x);
    scanf("%lld", &y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  long long kount = 0, has = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      cc = 0;
      dfs(i);
      has++;
      kount += min(cc, k);
    }
  }
  kount /= 2;
  if (k == 1) {
    long long ans = max(0LL, has - 2);
    printf("%lld\n", ans);
  } else {
    long long ans = max(0LL, (has - 1 - kount));
    printf("%lld\n", ans);
  }
  return 0;
}
