#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n, m, k;
int kd, d[maxn], a, b;
vector<int> g[maxn];
bool u[maxn];
multiset<int> ss;
int dfs(int i) {
  u[i] = 1;
  int res = 1;
  for (int j = 0; j < g[i].size(); j++) {
    if (!u[g[i][j]]) res += dfs(g[i][j]);
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  kd = 0;
  for (int i = 0; i < n; i++) {
    if (!u[i]) {
      d[kd++] = dfs(i);
    }
  }
  int total = 0;
  for (int i = 0; i < kd; i++) {
    if (d[i] > k) d[i] = k;
    total += d[i];
    ss.insert(d[i]);
  }
  for (int i = 0;; i++) {
    if (total >= 2 * ((int)ss.size() - 1)) {
      cout << i << endl;
      break;
    }
    int a = *ss.begin();
    ss.erase(ss.begin());
    int b = *ss.begin();
    ss.erase(ss.begin());
    total = total - a - b + min(a + b, k);
    ss.insert(min(a + b, k));
  }
  return 0;
}
