#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
const int INF = 1000000001;
vector<int> G[MAXN + 1];
bool vis[MAXN + 1];
vector<int> CC;
int n, m, k;
int dfs(int v) {
  vis[v] = true;
  int ret = 1;
  for (__typeof((G[v]).begin()) u = (G[v]).begin(); u != (G[v]).end(); ++u)
    if (!vis[*u]) ret += dfs(*u);
  return ret;
}
int main(int argc, char *argv[]) {
  scanf("%d %d %d", &n, &m, &k);
  while (m--) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int t = 0;
  int s = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i])
      CC.push_back(min(k, dfs(i))), t += CC.back() == 1 ? 0 : CC.back(),
          s += CC.back() != 1;
  t = t - 2 * s + 2;
  if (k == 1)
    printf("%d\n", max(0, (int)CC.size() - 2));
  else
    printf("%d\n", (max(0, ((int)CC.size() - s) - t + 1)) / 2);
  return 0;
}
