#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int cnt, sum, ans;
bool vis[1000005];
vector<int> e[1000005];
vector<int> v;
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  cnt++;
  for (int i = 0; i < e[x].size(); i++) dfs(e[x][i]);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    dfs(i);
    if (cnt) v.push_back(min(k, cnt));
  }
  sort(v.begin(), v.end());
  if (k == 1) {
    printf("%d\n", max(0, (int)v.size() - 2));
    return 0;
  }
  for (int i = 0; i < v.size(); i++) sum += v[i];
  ans = v.size() - sum / 2 - 1;
  if (ans <= 0)
    printf("0\n");
  else
    printf("%d\n", ans);
  return 0;
}
