#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1000010;
int n, m, k, used[NMAX], num, cnt[NMAX], may[NMAX];
vector<int> g[NMAX];
void dfs(int v) {
  used[v] = 1;
  cnt[num]++;
  for (int i = 0; i < (int)g[v].size(); i++)
    if (!used[g[v][i]]) dfs(g[v][i]);
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < (int)m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(used, 0, sizeof(0));
  num = 0;
  memset(cnt, 0, sizeof(0));
  for (int i = 0; i < (int)n; i++)
    if (!used[i]) {
      dfs(i);
      num++;
    }
  if (k == 1) {
    cout << max(0, num - 2) << endl;
    return 0;
  }
  sort(cnt, cnt + num);
  reverse(cnt, cnt + num);
  for (int i = 0; i < (int)num; i++) may[i] = min(k, cnt[i]);
  int now = may[0], ans = 0;
  for (int i = 0; i < (int)num; i++)
    if (i) {
      if (now > 0)
        now += may[i] - 2;
      else {
        ans++;
        now++;
      }
    }
  cout << ans << endl;
}
