Vasya plays FreeDiv. In this game he manages a huge state, which has n cities and m two-way roads between them. Unfortunately, not from every city you can reach any other one moving along these roads. Therefore Vasya decided to divide the state into provinces so that in every province, one could reach from every city all the cities of the province, but there are no roads between provinces. 

Unlike other turn-based strategies, in FreeDiv a player has the opportunity to build tunnels between cities. The tunnels are two-way roads along which one can move armies undetected by the enemy. However, no more than one tunnel can be connected to each city. As for Vasya, he wants to build a network of tunnels so that any pair of cities in his state were reachable by some path consisting of roads and a tunnels. But at that no more than k tunnels are connected to each province (otherwise, the province will be difficult to keep in case other provinces are captured by enemy armies).

Vasya discovered that maybe he will not be able to build such a network for the current condition of the state. Maybe he'll have first to build several roads between cities in different provinces to merge the provinces. Your task is to determine the minimum number of roads Vasya needs to build so that it was possible to build the required network of tunnels in the resulting state.

Input

The first line contains three integers n, m and k (1 ≤ n, k ≤ 106, 0 ≤ m ≤ 106). Each of the next m lines contains two integers. They are the numbers of cities connected by a corresponding road. No road connects city to itself and there is at most one road between each pair of cities.

Output

Print a single number, the minimum number of additional roads.

Examples

Input

3 3 2
1 2
2 3
3 1


Output

0

Input

4 2 2
1 2
3 4


Output

0

Input

4 0 2


Output

1

Note

In the first example only one province exists, so it is not necessary to build any tunnels or roads.

In the second example two provinces exist. It is possible to merge the provinces by building a tunnel between cities 1 and 3.

In the third example at least one additional road is necessary. For example it is possible to build additional road between cities 1 and 2 and build two tunnels between cities 1 and 3, 2 and 4 after that.
#include <bits/stdc++.h>
using namespace std;
int k, n, m;
vector<int> aa[1000010];
bool f[1000010];
int dfs(int v) {
  f[v] = true;
  int res = 1;
  for (int i = 0; i < int(aa[v].size()); i++) {
    int a = aa[v][i];
    if (!f[a]) res += dfs(a);
  }
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    aa[x].push_back(y);
    aa[y].push_back(x);
  }
  int s = 2;
  int q = 0;
  for (int i = 1; i <= n; i++)
    if (!f[i]) {
      s += min(dfs(i), k) - 2;
      q++;
    }
  if (k == 1)
    cout << max(q - 2, 0);
  else if (s >= 0)
    cout << 0;
  else
    cout << (-s + 1) / 2;
}
