#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const int inf = (-1u) >> 1;
bool v[maxn];
int n, m, k, num;
vector<int> g[maxn];
void dfs(int x) {
  v[x] = true;
  ++num;
  for (vector<int>::iterator it = g[x].begin(); it != g[x].end(); ++it) {
    if (!v[*it]) {
      dfs(*it);
    }
  }
}
int main() {
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    for (int i = 0; i < (n); ++i) {
      g[i].clear();
      v[i] = false;
    }
    for (int i = 0; i < (m); ++i) {
      int a, b;
      scanf("%d%d", &a, &b);
      --a, --b;
      g[a].push_back(b), g[b].push_back(a);
    }
    int cnt = 0, ecnt = 0, totcnt = 0;
    for (int i = 0; i < (n); ++i)
      if (!v[i]) {
        num = 0;
        dfs(i);
        ++totcnt;
        if (num == 1) {
          ++cnt;
        } else {
          ecnt += min(k, num) - 2;
        }
      }
    if (k >= 2) {
      ecnt += 2;
      cnt -= ecnt;
      if (totcnt > cnt) cnt += 2;
      printf("%d\n", max(0, (cnt - 1) / 2));
    } else {
      printf("%d\n", max(0, totcnt - 2));
    }
  }
  return 0;
}
