#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool vis[1000100];
multiset<int> ss;
vector<int> ga[1000100];
int sz[1000100];
int dfs(int u) {
  vis[u] = true;
  int ret = 1;
  for (int i = 0; i < ga[u].size(); i++) {
    int v = ga[u][i];
    if (!vis[v]) ret += dfs(v);
  }
  return ret;
}
int a, b;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    ga[a].push_back(b);
    ga[b].push_back(a);
  }
  int id = 0;
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      id++;
      sz[id] = dfs(i);
      sz[id] = min(sz[id], k);
      ss.insert(sz[id]);
      tot += sz[id];
    }
  }
  for (int i = 0; 1; i++) {
    if (tot >= (ss.size() - 1) * 2) {
      cout << i << endl;
      return 0;
    }
    int a = *(ss.begin());
    ss.erase(ss.begin());
    int b = *(ss.begin());
    ss.erase(ss.begin());
    tot = (tot - a - b + min(a + b, k));
    ss.insert(min(a + b, k));
  }
  return 0;
}
