#K966. Smallest Isolated Region

    ID: 39079 Type: Default 1000ms 256MiB

Smallest Isolated Region

Smallest Isolated Region

You are given n islands numbered from 1 to n and m bidirectional bridges connecting these islands. Island 1 is considered the "mainland", and all islands reachable from island 1 are part of the mainland region. Your task is to determine the size of the smallest isolated sub-region (i.e. a connected component) of islands that cannot be reached from the mainland. If every island is connected to the mainland, output -1.

The connectivity is defined by the bridges connecting the islands. Two islands belong to the same isolated region if there exists a path (sequence of bridges) connecting them which does not go through the mainland. Note that an isolated region may consist of a single island.

Note: All formulas use LaTeX formatting. For example, the number of islands is given by \( n \), and the number of bridges is given by \( m \).

inputFormat

The first line contains two space-separated integers \( n \) and \( m \), representing the number of islands and the number of bridges respectively.

The next \( m \) lines each contain two space-separated integers \( u \) and \( v \), indicating there is a bridge connecting island \( u \) and island \( v \).

If \( m = 0 \), then no further lines follow.

outputFormat

Output a single integer representing the size of the smallest isolated sub-region (component) which is not reachable from the mainland (island 1). If no isolated sub-region exists, output -1.

## sample
7 6
1 2
1 3
2 4
2 5
4 5
6 7
2