Houses in Berland
InterviewTime limit2sMemory limit1024 MB
Find the shortest distance between two residential houses with different resident counts in a connected graph of crossroads and roads.
Statement
The capital of Berland has crossroads. Some of them have residential houses. Let be the number of people in the family living in the house at crossroad , for all . If is 0, crossroad has no house.
Some crossroads are connected by roads. Berland has roads. Each road can be traveled in either direction. Each road connects two different crossroads, and any two crossroads are connected by at most one road. You can reach any crossroad from any other crossroad by roads. The distance between crossroads and is the minimum number of roads on a path from to .
When one family visits another, each person pairs up with exactly one person from the other family, and the two talk together. Two families find the visit boring if some person is left without a partner.
For reasons unknown, the government of Berland asks you to find two residential houses and such that if the family in house visits the family in house , the visit is boring. That means , , , and the distance from to is minimal. It is guaranteed that two residential houses with different numbers of residents exist.
Input
The first line contains and (, ), the number of crossroads and the number of two-way roads.
The second line contains integers ().
Each of the next lines contains two integers and (, ), the crossroads connected by the -th road.
Output
Print one integer: the minimum distance between two residential houses with different numbers of residents.
Hint
In the first example, only crossroads 1 and 3 have houses, and their residents differ. The distance between them is 2, and the shortest path uses roads 1 and 2.