#P8014. [COCI 2013/2014 #4] SUMO

[COCI 2013/2014 #4] SUMO

Problem Description

There are NN players participating in MM one-on-one matches, and the match order has already been fixed.

Now you need to divide these players into 22 teams, so that players meet opponents from the same team as late as possible.

Output the match index of the first match in which a player meets a player from the same team, under the optimal division.

Input Format

The first line contains a positive integer NN, meaning there are NN players.

The second line contains a positive integer MM, meaning there are MM matches.

The next MM lines each contain two positive integers AiA_i and BiB_i, meaning the players in match ii are player AiA_i and player BiB_i.

Output Format

Output one line containing a positive integer, the match index of the first match in which a player meets a player from the same team under the optimal team division.

5
5
1 2
2 3
3 4
4 5
5 1
5
6
8
1 2
3 4
5 6
1 3
1 6
4 5
2 4
2 6

6

Hint

Sample Explanation #1

[1,3,5][1,3,5] are in one team, and [2,4][2,4] are in the other team.

It can be proven that this is the optimal division.

Constraints

For 100%100\% of the testdata, 1Ai,BiN1051\le A_i,B_i\le N\le 10^5 and 1M3×1051\le M\le 3\times 10^5.

Source

The score of this problem follows the original COCI settings, with a full score of 100100.

Translated from COCI2013-2014 CONTEST #4 T3 SUMO

Translated by ChatGPT 5