#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int N = 1000005;
int c[N];
int c_count = 0;
int cc[N];
int c_out[N];
int avail[N];
int heap[N];
vector<vector<int> > g;
void dfs(int v) {
  int p = c[v];
  for (vector<int>::iterator i = g[v].begin(); i != g[v].end(); ++i) {
    if (c[*i] == 0) {
      c[*i] = p;
      ++cc[p];
      dfs(*i);
    }
  }
}
bool check(int a, int b) {
  if (avail[a] == avail[b]) {
    return c_out[a] > c_out[b];
  }
  return avail[a] < avail[b];
}
bool check_size(int a, int b) { return cc[a] > cc[b]; }
int s[N];
int main() {
  scanf("%d %d %d", &n, &m, &k);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf(" %d %d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; ++i) {
    if (c[i] == 0) {
      c[i] = ++c_count;
      ++cc[c_count];
      dfs(i);
      avail[c_count] = min(cc[c_count], k);
    }
  }
  for (int i = 1; i <= c_count; ++i) {
    s[i - 1] = i;
  }
  sort(&s[0], &s[c_count], check_size);
  heap[0] = s[0];
  int heapl = 1;
  int result = 0;
  for (int ii = 1; ii < c_count; ++ii) {
    int i = s[ii];
    int best = heap[0];
    ;
    ;
    if (avail[best] > 0) {
      ++c_out[best];
      ++c_out[i];
      --avail[best];
      --cc[best];
      --avail[i];
      --cc[i];
      pop_heap(&heap[0], &heap[heapl], check);
      push_heap(&heap[0], &heap[heapl], check);
      heap[heapl++] = i;
      push_heap(&heap[0], &heap[heapl], check);
      ;
      ;
      ;
    } else {
      ;
      cc[best] += cc[i];
      avail[best] = min(cc[best], k - c_out[best]);
      ;
      ;
      ;
      ++result;
    }
  }
  cout << result << endl;
}
