#include <bits/stdc++.h>
using namespace std;
const int MX = 1000 * 1000 + 50;
vector<int> adj[MX];
int n, m, k;
int comp[MX];
bool mark[MX], mar[MX];
int sum;
void DFS(int v, int color) {
  mark[v] = true;
  comp[color]++;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    if (!mark[adj[v][i]]) DFS(adj[v][i], color);
  }
  return;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int cn = 0;
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) {
      DFS(i, cn);
      cn++;
    }
  }
  for (int i = 0; i < cn; i++) {
    comp[i] = min(k, comp[i]);
    sum += comp[i];
  }
  if (k == 1) {
    if (cn - 2 <= 0) {
      cout << 0 << endl;
    } else
      cout << cn - 2 << endl;
    return 0;
  }
  sum = (sum / 2) + 1;
  cn -= sum;
  if (cn <= 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << cn << endl;
  return 0;
}
