#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000005;
bool visit[maxN];
int n, m, k;
vector<int> vec[maxN];
inline int dfs(int v) {
  visit[v] = true;
  int ret = 0;
  for (int i = 0; i < (int)vec[v].size(); i++) {
    int tmp = vec[v][i];
    if (!visit[tmp]) ret += dfs(tmp);
  }
  return ret + 1;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  int cnt = 0, res = 0;
  for (int i = 1; i <= n; i++)
    if (!visit[i]) {
      cnt += min(dfs(i), k);
      res++;
    }
  if (k == 1) {
    cout << max(0, res - 2) << endl;
    return 0;
  }
  if (cnt >= 2 * res - 2)
    cout << "0" << endl;
  else
    cout << (2 * res - 2 - cnt + 1) / 2 << endl;
  return 0;
}
