#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int s[2000005], e[2000005];
int pred[2000005], last[2000005];
int one, c, sum = 2;
int f, r;
int q[5000005];
bool vis[1000005];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= m; ++i) {
    cin >> s[i] >> e[i];
    s[i + m] = e[i];
    e[i + m] = s[i];
  }
  for (int i = 1; i <= m * 2; ++i) {
    pred[i] = last[s[i]];
    last[s[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      f = 1, r = 0;
      q[++r] = i;
      vis[i] = 1;
      while (f <= r) {
        int fr = q[f], x;
        x = last[fr];
        while (x > 0) {
          if (!vis[e[x]]) {
            q[++r] = e[x];
            vis[e[x]] = 1;
          }
          x = pred[x];
        }
        ++f;
      }
      ++c;
      if (r > k) {
        r = k;
      }
      if (r == 1) {
        ++one;
      } else {
        sum += r - 2;
      }
    }
  }
  if (c == 1) {
    cout << "0\n";
    exit(0);
  }
  if (k == 1) {
    cout << c - 2 << '\n';
    exit(0);
  }
  if (one <= sum) {
    cout << "0\n";
    exit(0);
  } else {
    cout << (one - sum + 1) / 2 << '\n';
    exit(0);
  }
  return 0;
}
