#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1e18 + 5;
const long long mxn = 1e6 + 5;
const int mod = 1e9 + 7, pa = 1e6 + 7;
long long n, a[555555], u[555555], mx = 0, l[mxn], r[mxn];
long long c[555555], b[555555];
vector<int> g[mxn];
long long x, sum;
void dfs(int v, int p, int h = 0) {
  c[v] = a[v];
  x += a[v] * h;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v, h + 1);
    c[v] += c[to];
  }
}
void df(int v, int p) {
  sum = max(sum, x);
  for (auto to : g[v]) {
    if (to == p) continue;
    x -= c[to];
    c[v] -= c[to];
    x += c[v];
    c[to] += c[v];
    df(to, v);
    c[to] -= c[v];
    x -= c[v];
    c[v] += c[to];
    x += c[to];
  }
}
int sz[mxn], p[mxn];
int pr(int x) {
  if (p[x] == x) return x;
  return x = pr(p[x]);
}
void pl(int x, int y) {
  int o = pr(x);
  int pp = pr(y);
  if (o == pp) return;
  if (sz[o] < sz[pp]) swap(o, pp);
  p[pp] = o, sz[o] += sz[pp];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    pl(u, v);
  }
  for (int i = 1; i <= n; i++) {
    int v = pr(i);
    l[v] = min(sz[v], k);
  }
  multiset<int> vv;
  for (int i = 1; i <= n; i++)
    if (l[i] > 0) vv.insert(l[i]);
  int v = vv.size();
  while (vv.size() > 1) {
    int x = (*vv.rbegin()), y = 0;
    vv.erase(--vv.end());
    y = (*vv.rbegin());
    if (x + y < 2) {
      vv.insert(x);
      break;
    }
    vv.erase(--vv.end());
    vv.insert(x + y - 2);
  }
  if (k == 1) return cout << max(0, (int)(v)-2), 0;
  cout << vv.size() - 1;
  return 0;
}
