#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, m, k, par[maxn], siz[maxn], a, b, l, s;
int findparent(int x) {
  if (x == par[x])
    return x;
  else
    return par[x] = findparent(par[x]);
}
void merge(int x, int y) {
  x = findparent(x);
  y = findparent(y);
  if (x != y) {
    par[x] = y;
    siz[y] = siz[y] + siz[x];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  fill(siz, siz + n + 1, 1);
  for (int i = 1; i <= n; i++) par[i] = i;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    merge(a, b);
  }
  for (int i = 1; i <= n; i++)
    if (i == par[i]) {
      s = s + min(k, siz[i]);
      l++;
    }
  if (k == 1)
    cout << max(0, l - 2);
  else
    cout << max(0, l - s / 2 - 1);
}
