#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
const long long N = 1e6 + 100, OO = 724249387, T = (1 << 20) + 10,
                M = 998244353, P = 6151, SQ = 280, lg = 64;
long long n, m, k, num, ed, t;
vector<long long> v[N];
bool mark[N];
void dfs(long long x) {
  mark[x] = 1;
  num++;
  for (auto u : v[x])
    if (!mark[u]) dfs(u);
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (long long i = 1; i <= n; i++) {
    if (!mark[i]) {
      num = 0;
      dfs(i);
      ed += min(num, k);
      t++;
    }
  }
  ed /= 2;
  if (k == 1) return cout << max((long long)0, t - 2), 0;
  cout << max((long long)0, t - 1 - ed);
  return 0;
}
