#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 5;
vector<int> Adj[maxn];
int v[maxn], tsize;
int N, M, K;
void dfs(int x) {
  v[x] = 1;
  for (int i = 0; i < (int)Adj[x].size(); ++i) {
    if (!v[Adj[x][i]]) {
      dfs(Adj[x][i]);
    }
  }
  ++tsize;
}
int main() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 0; i < M; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    Adj[x].push_back(y);
    Adj[y].push_back(x);
  }
  multiset<int> con;
  for (int i = 1; i <= N; ++i) {
    if (!v[i]) {
      tsize = 0;
      dfs(i);
      con.insert(min(tsize, K));
    }
  }
  if (K == 1) {
    printf("%d\n", max((int)con.size() - 2, 0));
  } else {
    multiset<int>::iterator it;
    int sum = 0;
    for (it = con.begin(); it != con.end(); ++it) sum += *it;
    int ans;
    for (ans = 0;; ans++) {
      if (sum >= 2 * ((int)con.size() - 1)) {
        break;
      }
      tsize = 0;
      it = con.begin();
      tsize += *it;
      sum -= *it;
      con.erase(it);
      it = con.begin();
      tsize += *it;
      sum -= *it;
      con.erase(it);
      con.insert(min(tsize, K));
      sum += min(tsize, K);
    }
    printf("%d\n", ans);
  }
  return 0;
}
