#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int x, y;
int n, m, k, l;
vector<vector<int> > g;
long long have;
long long havek;
int comp[1 << 20];
int color[1 << 20];
inline void init() {
  scanf("%d%d%d", &n, &m, &k);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &x, &y);
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
}
void dfs(int x) {
  ++comp[color[x]];
  int k = (int)g[x].size();
  for (int i = 0; i < k; ++i) {
    int y = g[x][i];
    if (color[y] != -1) continue;
    color[y] = color[x];
    dfs(y);
  }
}
priority_queue<pair<int, int> > q;
int main() {
  init();
  l = 0;
  memset(comp, 0, sizeof comp);
  memset(color, -1, sizeof color);
  for (int i = 0; i < n; ++i) {
    if (color[i] != -1) continue;
    color[i] = l++;
    dfs(i);
  }
  for (int i = 0; i < l; ++i) comp[i] = min(comp[i], k);
  sort(comp, comp + l);
  reverse(comp, comp + l);
  int res = 0;
  q.push(pair<int, int>(comp[0], k - comp[0]));
  for (int i = 1; i < l; ++i) {
    pair<int, int> cur = q.top();
    q.pop();
    if (cur.first == 0) {
      ++res;
      int dif = min(cur.second, comp[i]);
      cur.first += dif;
      cur.second -= dif;
      q.push(cur);
      continue;
    }
    --cur.first;
    q.push(cur);
    q.push(pair<int, int>(comp[i] - 1, k - comp[i]));
  }
  printf("%d\n", res);
  return 0;
}
