#include <bits/stdc++.h>
using namespace std;
vector<int> v[1000001];
int n, m, k, a, b, cnt, sum;
bool vis[1000001];
int dfs(int a, int fa) {
  vis[a] = true;
  int ans = 1;
  for (int i = 0; i < v[a].size(); i++) {
    if (vis[v[a][i]]) continue;
    ans += dfs(v[a][i], a);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  while (m--) cin >> a >> b, v[a].push_back(b), v[b].push_back(a);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) sum += min(dfs(i, i), k), cnt++;
  if (k == 1)
    cout << max(cnt - 2, 0);
  else if (cnt == 1)
    cout << 0;
  else
    cout << max(0, cnt - 1 - sum / 2);
  return 0;
}
