#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 1000 + 50;
vector<int> v[maxN];
int cnt;
bool mark[maxN];
void dfs(int s) {
  mark[s] = 1;
  cnt++;
  for (int i = 0; i < v[s].size(); i++)
    if (mark[v[s][i]] == 0) dfs(v[s][i]);
}
int main() {
  int n, m, k, sum = 0, com = 0;
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (mark[i] == 0) {
      com++;
      cnt = 0;
      dfs(i);
      sum += min(k, cnt);
    }
  if (k == 1)
    cout << max(0, com - 2) << endl;
  else
    cout << max(0, com - 1 - (sum / 2)) << endl;
  return 0;
}
