#C6892. Optimal Metropolis

    ID: 50702 Type: Default 1000ms 256MiB

Optimal Metropolis

Optimal Metropolis

In this problem, you are given a network of metropolises connected by bidirectional roads. Your task is to determine the metropolis that minimizes the maximum distance to any other metropolis in its connected component. In other words, for each metropolis (i) in a connected component (C(i)), let its eccentricity be defined as (e(i) = \max_{j \in C(i)} d(i,j)), where (d(i,j)) is the shortest distance between metropolis (i) and metropolis (j). Your goal is to choose the metropolis with the smallest eccentricity. In case of a tie, choose the metropolis with the smallest index.

Note: If the graph is disconnected, only metropolises that are connected (i.e. have at least one road) are considered for selecting the optimal metropolis. However, if there is only one metropolis (even if isolated), output that metropolis's index.

inputFormat

The first line of input contains two integers (n) and (m) (with (1 \leq n \leq 10^5)) representing the number of metropolises and the number of roads respectively. Each of the following (m) lines contains two integers (u) and (v) ((1 \leq u,v \leq n)) indicating that there is a bidirectional road between metropolis (u) and metropolis (v). The input is provided via standard input (stdin).

outputFormat

Output a single integer to the standard output (stdout): the index of the metropolis with the minimum eccentricity in its connected component. In case of ties, output the smallest index.## sample

4 3
1 2
2 3
2 4
2