#include <bits/stdc++.h>
using namespace std;
vector<int> gr[1100000];
int comp[1100000];
int n;
int dfs(int v, int c) {
  if (comp[v]) return 0;
  int r = 1;
  comp[v] = c;
  for (int i = 0; i < (int)gr[v].size(); ++i) r += dfs(gr[v][i], c);
  return r;
}
int main() {
  cin >> n;
  int m, k;
  cin >> m >> k;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  int c = 0;
  int ones = 0;
  int s = 0;
  bool was = false;
  for (int i = 0; i < (n); ++i)
    if (!comp[i]) {
      int t = dfs(i, ++c);
      t = min(t, k);
      if (t == 1)
        ++ones;
      else {
        s += t - 2;
        was = true;
      }
    }
  if (k == 1) {
    cout << max(0, c - 2);
    return 0;
  }
  cout << max(0, (ones - s - 1) / 2);
  return 0;
}
