#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 9;
const double eps = 1e-5;
const int maxN = 1e6 + 5;
const int inf = 1e9;
int n, m, k;
int cl;
vector<int> G[maxN];
bool vis[maxN];
int sz[maxN];
inline void dfs(int v, int c) {
  vis[v] = 1;
  sz[c]++;
  for (int i = 0; i < G[v].size(); i++)
    if (!vis[G[v][i]]) dfs(G[v][i], c);
}
inline void init() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0, a, b; i < m; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}
inline void solve() {
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i, cl);
      cl++;
    }
  }
  int TF = 0;
  for (int i = 0; i < cl; i++) TF += min(k, sz[i]);
  printf("%d\n", max(0, (k == 1) ? cl - 2 : cl - 1 - (int)(TF / 2)));
}
int main() {
  init();
  solve();
  return 0;
}
