#include <bits/stdc++.h>
using namespace std;
int n, m, k, f[10000005], t;
int h[10000005], adj[10000005], nxt[10000005], o, ans;
inline void add(int u, int v) {
  nxt[++o] = h[u];
  h[u] = o;
  adj[o] = v;
  return;
}
inline int dfs(int u) {
  f[u] = 1;
  for (int i = h[u]; ~i; i = nxt[i]) {
    int v = adj[i];
    if (!f[v]) f[u] += dfs(v);
  }
  return f[u];
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  memset(h, -1, sizeof(h));
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; ++i)
    if (!f[i]) {
      ans += min(dfs(i), k);
      ++t;
    }
  if (k == 1)
    printf("%d\n", max(0, t - 2));
  else if (t == 1)
    puts("0");
  else
    printf("%d\n", max(0, t - (ans >> 1) - 1));
  return 0;
}
