There are n planets in the galaxy, and many undirected warp tunnels connecting them. 6000 years ago, Spinel performed a depth-first search on the planets, visited all of them, and labeled them from 1 to n in the order of discovery.
Many warp tunnels have broken down since, and only

of them are still working. Spinel wants to know how many new warp tunnels have to be built so that it is possible to perform a depth-first search, where the order of discovery is exactly as labeled

years ago.
Recall that the depth-first search (DFS) algorithm inputs a graph

and a vertex

of

, and labels all vertices reachable from

as discovered.
Here is the pseudocode of a recursive implementation of DFS:
procedure DFS(G, v) is
label v as discovered
for all vertices w that there exists an edge between v and w do
if vertex w is not labeled as discovered then
recursively call DFS(G, w)