#include <bits/stdc++.h>
using namespace std;
int n, m, k, cnt = 0, num = 0;
bool vis[1000004];
vector<int> g[1000004];
int dfs(int x) {
  int res = 1;
  vis[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    if (vis[g[x][i]]) continue;
    res += dfs(g[x][i]);
  }
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int pp;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    num += min(dfs(i), k);
    cnt++;
  }
  if (k == 1) {
    cout << max(0, cnt - 2);
    return 0;
  }
  int tt = 2 * (cnt - 1) - num;
  if (tt <= 0) return !printf("0");
  int oo = num / 2;
  cout << cnt - 1 - oo;
  return 0;
}
