#include <bits/stdc++.h>
using namespace std;
const double pie1 = 3.1415926;
const double pie2 = 3.14159265358979;
const double pie3 = 3.14159265358979323846;
const int vbi = 999999999;
const int vli = -vbi;
const long long vbl = 999999999999999999;
const long long vll = -vbl;
priority_queue<int> pqi;
priority_queue<long long> pql;
queue<int> qi;
queue<long long> ql;
bool pss(int a) {
  for (int i = 2; i <= sqrt(a); i++)
    if (a % i == 0) return false;
  return true;
}
vector<int> v[1000010];
int q[1000010];
bool vis[1000010];
int main() {
  ios::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int s1 = 0, ns1 = 2, sss = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      vis[i] = true;
      int l = 1, r = 1;
      q[1] = i;
      while (r - l + 1 > 0) {
        int now = q[l];
        for (int j = 0; j < v[now].size(); j++)
          if (!vis[v[now][j]]) {
            vis[v[now][j]] = true;
            r++;
            q[r] = v[now][j];
          }
        l++;
      }
      sss++;
      if (r > k) r = k;
      if (r == 1)
        s1++;
      else
        ns1 += r - 2;
    }
  }
  if (sss == 1)
    cout << 0;
  else if (k == 1)
    cout << sss - 2;
  else if (s1 <= ns1)
    cout << 0;
  else
    cout << (s1 - ns1 + 1) / 2;
  return 0;
}
