#ABC239F. [ABC239F] Construct Highway

[ABC239F] Construct Highway

Score : 500500 points

Problem Statement

The Republic of Atcoder has NN towns numbered 11 through NN, and MM highways numbered 11 through MM. Highway ii connects Town AiA_i and Town BiB_i bidirectionally.

King Takahashi is going to construct (NM1)(N-M-1) new highways so that the following two conditions are satisfied:

  • One can travel between every pair of towns using some number of highways
  • For each i=1,,Ni=1,\ldots,N, exactly DiD_i highways are directly connected to Town ii

Determine if there is such a way of construction. If it exists, print one.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 0M<N10 \leq M \lt N-1
  • 1DiN11 \leq D_i \leq N-1
  • 1Ai<BiN1\leq A_i \lt B_i \leq N
  • If iji\neq j, then (Ai,Bi)(Aj,Bj)(A_i, B_i) \neq (A_j,B_j).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

D1D_1 \ldots DND_N

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

If there isn't a way of construction that satisfies the conditions, print -1. If there is, print (NM1)(N-M-1) lines. The ii-th line should contain the indices of the two towns connected by the ii-th highway to be constructed.

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

As in the Sample Output, the conditions can be satisfied by constructing highways connecting Towns 66 and 22, Towns 55 and 66, and Towns 44 and 55, respectively.

Another example to satisfy the conditions is to construct highways connecting Towns 66 and 44, Towns 55 and 66, and Towns 22 and 55, respectively.

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