#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 1;
vector<int> ng[MAXN];
bool mark[MAXN];
vector<int> comps[MAXN];
void dfs(int x, int id) {
  mark[x] = true;
  comps[id].push_back(x);
  for (int i = 0; i < ng[x].size(); i++)
    if (!mark[ng[x][i]]) dfs(ng[x][i], id);
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ng[a].push_back(b);
    ng[b].push_back(a);
  }
  int compCnt = 0, sum = 0;
  for (int i = 0; i < n; i++)
    if (!mark[i]) {
      dfs(i, compCnt);
      compCnt++;
    }
  int ones = 0;
  for (int i = 0; i < compCnt; i++) sum += min(k, (int)comps[i].size());
  if (k == 1)
    cout << max(compCnt - 2, 0) << endl;
  else
    cout << max(0, compCnt - sum / 2 - 1) << endl;
  return 0;
}
