#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-15;
double PI = 3.14159265359;
const long long INF = 1e8;
const int N = 1000001;
vector<vector<int> > G;
vector<int> cmp;
int n, m, k, a, b, V[N], res = 0;
int dfs(int u) {
  V[u] = 1;
  int ret = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (V[v]) continue;
    ret += dfs(v);
  }
  return ret;
}
struct state {
  int ka, ktg, c, ku;
  bool operator()(state s1) {
    if (this->ka || s1.ka) return this->ka < s1.ka;
    return this->ktg < s1.ktg;
  }
};
struct compare {
  bool operator()(state a, state b) {
    if (a.ka || b.ka) return a.ka < b.ka;
    return a.ktg < b.ktg;
  }
};
bool comp(int u, int v) { return u > v; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  G.resize(N);
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (!V[i]) cmp.push_back(dfs(i));
  sort(cmp.begin(), cmp.end(), comp);
  priority_queue<state, vector<state>, compare> q;
  state tm = state();
  tm.ka = min(cmp[0], k);
  tm.ku = 0;
  tm.ktg = k - tm.ku;
  tm.c = cmp[0];
  q.push(tm);
  for (int i = 1; i < cmp.size(); i++) {
    state st = q.top();
    q.pop();
    int cc = cmp[i];
    if (st.ka) {
      st.ka = min(st.c - 1, st.ka - 1);
      st.ku++;
      st.ktg = k - st.ku - st.ka;
      state ss = state();
      ss.c = cc;
      ss.ku++;
      ss.ktg = k - ss.ku - st.ka;
      ss.ka = min(k - 1, cc - 1);
      q.push(st);
      q.push(ss);
    } else {
      res++;
      st.c += cc;
      if (st.ktg) {
        st.ktg--;
        st.ka = min(k, st.c - st.ku);
        q.push(st);
      }
    }
  }
  cout << res;
}
