#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 1000 + 321;
vector<int> a[maxN];
int mark[maxN];
int comper[maxN];
void dfs(int v, int comp) {
  mark[v] = comp;
  comper[comp]++;
  for (int i = 0; i < a[v].size(); i++) {
    int u = a[v][i];
    if (!mark[u]) dfs(u, comp);
  }
}
int main() {
  ios::sync_with_stdio(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int d, k;
    cin >> d >> k;
    d--;
    k--;
    a[d].push_back(k);
    a[k].push_back(d);
  }
  int comp = 1;
  for (int i = 0; i < n; i++)
    if (!mark[i]) {
      dfs(i, comp);
      comp++;
    }
  int count = 0;
  for (int i = 1; i < comp; i++) count += min(k, comper[i]);
  comp--;
  if (count % 2) count--;
  int ans = 0;
  if (k == 1) {
    cout << max(0, comp - 2) << endl;
    return 0;
  };
  if (count >= 2 * comp - 2)
    cout << '0' << endl;
  else
    cout << (2 * comp - 2 - count) / 2 << endl;
  return 0;
}
