#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 20;
int n, m, k;
int vist[MAX];
int head[MAX], nxt[MAX << 1], to[MAX << 1], ent;
void add(int a, int b) {
  nxt[ent] = head[a], to[ent] = b, head[a] = ent++;
  nxt[ent] = head[b], to[ent] = a, head[b] = ent++;
}
void print() {
  for (int i = 1; i <= n; i++) {
    printf("v = %d: ", i);
    for (int j = head[i]; ~j; j = nxt[j]) printf("%d->", to[j]);
    printf("\n");
  }
}
int isoN;
int cnt;
int pn[MAX];
int cn;
void dfs(int v, int pa) {
  vist[v] = 1, cn++;
  for (int i = head[v]; ~i; i = nxt[i]) {
    int u = to[i];
    if (u != pa && vist[u] == 0) {
      dfs(u, v);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  ent = 0;
  memset(head, -1, sizeof(head));
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b);
  }
  isoN = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (vist[i] == 0) {
      cn = 0;
      dfs(i, -1);
      if (cn == 1)
        isoN++;
      else
        pn[cnt++] = cn;
    }
  }
  if (k == 1) {
    if (isoN + cnt != 1)
      printf("%d\n", isoN + cnt - 2);
    else
      printf("%d\n", 0);
  } else {
    int ans;
    int d2 = 0, d1 = 0, t3, t4 = 0;
    ;
    for (int i = 0; i < cnt; i++) {
      pn[i] = std::min(pn[i], k);
      if (pn[i] == 1)
        d1++;
      else
        d2++, t3 = pn[i], t4 += pn[i];
    }
    if (d2 == 0) {
      int t1 = d1 + isoN;
      ans = (t1 + 1) / 2 - 1, printf("%d\n", ans);
    } else if (d2 == 1) {
      isoN += d1;
      if (isoN <= t3)
        printf("%d\n", 0);
      else {
        int t5 = isoN - t3;
        printf("%d\n", (t5 + 1) / 2);
      }
    } else {
      isoN += d1;
      t4 -= (d2 - 1) * 2;
      if (isoN > t4)
        printf("%d\n", (isoN - t4 + 1) / 2);
      else
        printf("%d\n", 0);
    }
  }
  return 0;
}
