#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, m, k, cnt, sum, cmp;
bool mark[maxn];
vector<int> nei[maxn];
void dfs(int v) {
  mark[v] = true;
  cnt++;
  for (auto u : nei[v])
    if (!mark[u]) dfs(u);
}
void dfs_all() {
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      cnt = 0;
      dfs(i);
      sum += min(cnt, k);
      cmp++;
    }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    nei[a].push_back(b);
    nei[b].push_back(a);
  }
  dfs_all();
  if (k == 1)
    cout << max(cmp - 2, 0) << endl;
  else
    cout << max(0, cmp - 1 - sum / 2) << endl;
}
