#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(T a, int n) {
  for (int i = 0; i < n; ++i) cout << a[i] << ' ';
  cout << endl;
}
template <class T>
void show(T a, int r, int l) {
  for (int i = 0; i < r; ++i) show(a[i], l);
  cout << endl;
}
const int N = 1 << 20;
const int M = 5000;
const int oo = 10000 * 10000 * 10;
int n, m, q;
bool visited[N];
vector<int> e[N];
int que[N];
int bfs(int s) {
  int i, j, k;
  int u, v;
  int head = 0;
  int tail = 0;
  int cnt = 0;
  que[tail++] = s;
  visited[s] = true;
  ++cnt;
  while (head != tail) {
    u = que[head++];
    for (i = 0; i < e[u].size(); ++i) {
      int v = e[u][i];
      if (!visited[v]) {
        visited[v] = true;
        ++cnt;
        que[tail++] = v;
      }
    }
  }
  return cnt;
}
void solve() {
  memset(visited, 0, sizeof(visited));
  int i, j, k;
  priority_queue<int, vector<int>, greater<int> > pq;
  int sum = 0;
  int tn = 0;
  for (i = 1; i <= n; ++i) {
    if (!visited[i]) {
      int c = bfs(i);
      int t = (c < q ? c : q);
      pq.push(t);
      sum += t;
      ++tn;
    }
  }
  int ans = 0;
  while (sum < (tn - 1) * 2) {
    int t1 = pq.top();
    pq.pop();
    int t2 = pq.top();
    pq.pop();
    int t3 = (q < t1 + t2 ? q : t1 + t2);
    pq.push(t3);
    sum -= t1 + t2 - t3;
    tn--;
    ++ans;
  }
  printf("%d\n", ans);
}
int main() {
  int i, j, cas = 0;
  scanf("%d %d %d", &n, &m, &q);
  for (i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  solve();
  return 0;
}
