#include <bits/stdc++.h>
using namespace std;
int pred[2000010], last[1000005];
int s[2000010], f[2000010];
bool visit[1000005];
int x[1000005];
long long k1, sum, kc, fr, re, j;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s[i], &f[i]);
    s[i + m] = f[i];
    f[i + m] = s[i];
  }
  for (int i = 1; i <= m + m; i++) {
    pred[i] = last[s[i]];
    last[s[i]] = i;
  }
  k1 = 0, sum = 2;
  kc = 0;
  for (int i = 1; i <= n; i++) {
    if (!visit[i]) {
      fr = 1, re = 1;
      x[1] = i;
      visit[i] = 1;
      while (fr <= re) {
        j = last[x[fr]];
        while (j > 0) {
          if (!visit[f[j]]) {
            re++;
            x[re] = f[j];
            visit[x[re]] = 1;
          }
          j = pred[j];
        }
        fr++;
      }
      kc++;
      if (re > k) re = k;
      if (re == 1)
        k1++;
      else
        sum += re - 2;
    }
  }
  if (kc == 1)
    cout << 0 << endl;
  else if (k == 1)
    cout << kc - 2 << endl;
  else if (k1 <= sum)
    cout << 0 << endl;
  else
    cout << (k1 - sum + 1) / 2 << endl;
  return 0;
}
