There was a tennis tournament held recently and Sylvie was following the matches when she noticed something odd. She knows for a fact that in this tournament someone will win against someone else if and only if they are better than them and there is no draw in the games.
She observed that some winning loops were formed in the tournament, meaning that if among players z1 to zk, for each i from 1 to k−1, zi had won against zi+1, then the player zk had won against z1 which should be impossible. Therefore, she suspected that there was some doping involved.
She wanted to report it to the tournament organizer so they can act accordingly but to prove her point she wanted to give them an example. She decided to provide them with the smallest loop possible so verifying it would not be so hard. Now, you have to help her find the smallest loop.
In other words, there is a directed graph and you have to find the smallest cycle possible.
Note: The graph does not have any self-loops but multiple edges are allowed.
Input format
Output format
Note: If there is no winning loop in the tournament (cycle in the graph), then print −1 in the only line of output.
Constraints
1≤n,m≤105
Scoring
If there is no cycle, your answer is considered as 2×n in the scoring.
In this sample, edges (4, 5), (5, 6), (6, 7), (7, 4) construct a cycle of length 4. However, this is not the minimum cycle that exists, because edges (4, 1), (7, 4), (1, 7) form a cycle of length 3.