#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const double PI = 3.14159265359;
vector<int> g[maxn], p;
bool mark[maxn];
int dfs(int v) {
  mark[v] = 1;
  int ans = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (!mark[u]) ans += dfs(u);
  }
  return ans;
}
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(0);
  int n, m, k, a, b, ans = 0, po, pp;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    g[a].push_back(b), g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (!mark[i]) p.push_back(min(k, dfs(i)));
  sort(p.begin(), p.end(), cmp);
  po = p[0];
  for (int i = 1; i < p.size(); i++)
    if (po == 0)
      po = pp, p[i] = min(k, p[i] + p[i - 1]), p[i - 1] = 2, ans++, i--;
    else
      pp = po, po += p[i] - 2;
  cout << ans << endl;
  return 0;
}
