#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
const int N = 1e6 + 20;
vector<int> G[N];
bool visited[N];
int n, m, k, com[N], sz[N], cnt, ans;
void dfs(int v, int p) {
  visited[v] = 1;
  com[v] = p;
  sz[p]++;
  for (int u : G[v])
    if (!visited[u]) dfs(u, p);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0, v, u; i < m; i++) {
    cin >> v >> u;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  for (int i = 1; i <= n; i++)
    if (!visited[i]) dfs(i, ++cnt);
  if (cnt == 1) return cout << 0 << endl, 0;
  if (k == 1) return cout << max(cnt - 2, 0) << endl, 0;
  for (int i = 1; i <= cnt; i++) ans += min(sz[i], k);
  cout << max(0, cnt - ans / 2 - 1) << endl;
}
