#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
const int MOD = 998244353, N = 1e6 + 5, INF = INT_MAX;
vector<int> v[N], c;
bool ch[N];
int num = 0;
int dfs(int u) {
  ch[u] = true;
  int ans = 1;
  for (int i = 0; i < v[u].size(); i++) {
    if (!ch[v[u][i]]) ans += dfs(v[u][i]);
  }
  return ans;
}
int main() {
  cin.sync_with_stdio(false), cin.tie(NULL);
  int n, m, k;
  cin >> n >> m >> k;
  int u, w;
  for (int i = 0; i < m; i++) {
    cin >> u >> w;
    v[u].push_back(w);
    v[w].push_back(u);
  }
  int f = 0, ans = 0, tp2, s = 0;
  for (int i = 1; i <= n; i++) {
    if (!ch[i]) {
      tp2 = dfs(i);
      if (min(tp2, k) == 1)
        ans++;
      else
        s += min(tp2, k) - 2;
      f++;
    }
  }
  ans -= s;
  int tp;
  if (f == 1 || ans <= 0)
    ans = 0;
  else if (k == 1)
    ans = f - 2;
  else {
    tp = ans;
    ans = tp / 2;
    if (tp % 2 == 0) ans--;
  }
  cout << ans << endl;
  return 0;
}
