Glassworks

Time limit: 1s Memory limit: 128MB Input: Output:

Giorgio and Edoardo are planning to go on a tour of Venice, and they are particularly interested in Murano’s famous colored Venetian glass.

There are NN shops which sell glasswares and they are numbered from 00 to N1N − 1, the ii-th shop sells only pieces of color CiC_i. Giorgio and Edoardo are interested in visiting some shop and buying some glasswares, they will be happy if they have bought glasswares of at least 33 different colors.

The fastest (and the only one) way to travel in Murano is by gondola, in particular there are MM gondolas, each gondola can carry Giorgio and Edoardo from shop AiA_i to BiB_i and viceversa. However, gondolas are not free and each trip requires a ticket (each ticket is valid for one trip only, so taking the same gondola twice requires two tickets).

Giorgio and Edoardo can start and finish the tour in any shop, help them find the minimum number of tickets required to buy at least 33 glasswares of different colors, or tell that they can’t.

Input data

The first line contains the integers NN and MM, the number of shops and the number of available gondolas. The second line contains NN integers, CiC_i for ii = 0N10 \dots N − 1.

The following MM lines contain 22 integers AiA_i and BiB_i each, meaning that a gondola can travel between shops AiA_i and BiB_i.

Output data

You need to write a single line with an integer: the minimum number of tickets Giorgio and Edoardo need or 1−1 if they can’t visit shops with glasswares of 33 different colors.

Constraints and clarifications

  • 2N500 0002 \leq N \leq 500 \ 000;
  • 1M500 0001 \leq M \leq 500 \ 000;
  • 0CiN10 \leq C_i \leq N - 1;
  • 0Ai,BiN10 \leq A_i, B_i \leq N - 1, AiBiA_i \neq B_i;
# Score Constraints
1 0 Examples
2 20 N,M500N, M \leq 500
3 20 N,M1 000N, M \leq 1 \ 000
4 20 For each ii = 0N10 \dots N − 1, there are at most two values of jj for which AjA_j = ii or BjB_j = ii.
5 40 No additional limitations.

Example 1

stdin

6 6
2 0 1 1 2 1
0 2
1 3
1 5
2 4
2 5
3 5

stdout

3

Explanation

In the first sample case it is possible to start the tour in shop 44, go to shop 22, then go to shop 55 and end the tour in shop 11.

Example 2

stdin

5 3
0 0 1 2 3
0 1
2 1
3 4

stdout

-1

Explanation

In the second sample case it isn’t possible to plan a tour that passes by shops which have glass of 33 different colors.

Log in or sign up to be able to send submissions!