#include <bits/stdc++.h>
#pragma GCC optmize(2)
using namespace std;
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
int f[1000010];
vector<int> G[1000010];
int vis[1000010];
int tot, s, cnt;
int dfs(int i) {
  int res = 1;
  vis[i] = 1;
  for (int j = 0; j < G[i].size(); j++) {
    if (!vis[G[i][j]]) res += dfs(G[i][j]);
  }
  return res;
}
multiset<int> ss;
int n = read(), m = read(), k = read();
int main() {
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    G[x].push_back(y), G[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) f[++tot] = dfs(i);
  sort(f + 1, f + tot + 1);
  reverse(f + 1, f + tot + 1);
  int total = 0;
  for (int i = 1; i <= tot; i++) {
    f[i] = min(f[i], k);
    total += f[i];
    ss.insert(f[i]);
  }
  for (int i = 0;; i++) {
    if (total >= 2 * ((int)ss.size() - 1)) {
      cout << i << endl;
      return 0;
    }
    int a = *ss.begin();
    ss.erase(ss.begin());
    int b = *ss.begin();
    ss.erase(ss.begin());
    total = total - a - b + min(a + b, k);
    ss.insert(min(a + b, k));
  }
  return 0;
}
