#include <bits/stdc++.h>
using namespace std;
vector<bool> was;
int dfs(int x, vector<vector<int> > &g) {
  was[x] = true;
  int ans = 1;
  for (int i = 0; i < g[x].size(); ++i) {
    if (!was[g[x][i]]) {
      ans += dfs(g[x][i], g);
    }
  }
  return ans;
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int> > g(n);
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    g[l].push_back(r);
    g[r].push_back(l);
  }
  was = vector<bool>(n, false);
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    if (!was[i]) {
      a.push_back(dfs(i, g));
    }
  }
  for (int i = 0; i < a.size(); ++i) a[i] = min(a[i], k);
  int c = a.size();
  int sum = 0;
  for (int i = 0; i < c; ++i) sum += a[i];
  if (sum >= 2 * (c - 1)) {
    cout << 0;
    return 0;
  }
  if (k == 1) {
    cout << c - 2;
  } else {
    int ans = 0;
    while (sum < 2 * (c - 1)) {
      --c;
      ++ans;
    }
    cout << ans;
  }
  return 0;
}
