#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> g[1000000 + 3];
int u, v;
int vis[1000000 + 3];
int cc = 0;
int deg[1000000 + 3];
int total_nodes_in_this_component = 0;
void dfs(int u) {
  total_nodes_in_this_component++;
  vis[u] = 1;
  for (int j = 0; j < g[u].size(); j++) {
    int v = g[u][j];
    if (vis[v] == 0) dfs(v);
  }
}
int over_all_degree_sum = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cc = 0;
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0) {
      cc++;
      total_nodes_in_this_component = 0;
      dfs(i);
      deg[cc] = total_nodes_in_this_component;
      over_all_degree_sum += min(total_nodes_in_this_component, k);
    }
  }
  int edge_required = cc - 1;
  int tunnel_required = 2 * edge_required;
  if (k == 1) {
    cout << max(cc - 2, 0) << endl;
    return 0;
  }
  if (over_all_degree_sum >= tunnel_required) {
    cout << 0 << endl;
    return 0;
  }
  int apatoto_edge_banano_gese = over_all_degree_sum / 2;
  int now_cc = cc - (apatoto_edge_banano_gese);
  int notun_edge_lagbe = (now_cc - 1);
  cout << notun_edge_lagbe << endl;
  return 0;
}
