#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
const long long mod = 1e9 + 7;
vector<int> g[maxn], a;
bool vis[maxn];
int dfs(int v) {
  vis[v] = true;
  int res = 1;
  for (auto u : g[v])
    if (!vis[u]) res += dfs(u);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    --v;
    --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  int one = 0, sum = 0, num = 0;
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      int cur = dfs(i);
      num++;
      sum += min(cur, k);
      if (cur == 1) one += cur;
    }
  if (num == 1) return cout << "0\n", 0;
  if (k == 1) return cout << num - 2 << "\n", 0;
  for (int i = 0; i <= one / 2; i++) {
    int cur = sum + 2 * i - 2 * num + 2;
    if (cur >= 0) return cout << i << "\n", 0;
  }
}
