#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1111111];
int sz[1111111], cnt;
bool vis[1111111];
int compdfs(int v) {
  vis[v] = true;
  sz[v] = 1;
  for (auto u : adj[v]) {
    if (!vis[u]) {
      sz[v] += compdfs(u);
    }
  }
  return sz[v];
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int q, w;
    cin >> q >> w;
    adj[q].push_back(w);
    adj[w].push_back(q);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      int tmp = compdfs(i);
      sum += min(tmp, k);
      cnt++;
    }
  }
  if (cnt == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    cout << max(cnt - 2, 0) << endl;
    return 0;
  }
  cout << max(0, cnt - sum / 2 - 1) << endl;
  return 0;
}
