#include <bits/stdc++.h>
using namespace std;
int fix[1000005];
int sum, ans, n, m, a, k, b, i, j, len, raod;
vector<int> g[1000005];
multiset<int> s;
void go(int v) {
  fix[v] = 1;
  raod++;
  for (int i = 0; i < g[v].size(); i++) {
    int nxt = g[v][i];
    if (!fix[nxt]) go(nxt);
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (i = 1; i <= n; i++)
    if (!fix[i]) {
      len++;
      raod = 0;
      go(i);
      raod = min(raod, k);
      sum += raod;
      s.insert(raod);
    }
  while (2 * (len - 1) > sum) {
    a = *s.begin();
    s.erase(s.begin());
    b = *s.begin();
    s.erase(s.begin());
    sum -= a + b;
    sum += min(a + b, k);
    ans++;
    s.insert(min(a + b, k));
    len--;
  }
  cout << ans << endl;
}
