#P15636. [2019 KAIST RUN Spring] Jealous Teachers

[2019 KAIST RUN Spring] Jealous Teachers

Problem Description

There are NN teachers and NN students in the Seoul Science High School. Each student bought NN flowers because tomorrow is a teacher's day in Korea. However, one of the students quit, and now only N1N-1 students remain in the school.

Teachers are very jealous, so they will give an F grade to students when they receive fewer flowers from that student than others. Therefore, every teacher should receive exactly N1N-1 flowers. A student can only give flowers to teachers who have taught him or her, and you know which students have learned from which teachers.

Younghun is the student of Seoul Science High School, and he needs your help in organizing this event.

Input Format

The first line contains two integers NN and MM (2N1000002 \le N \le 100 000, 1M2000001 \le M \le 200 000) describing the number of teachers and the number of (student, teacher) pairs where the student learned from the teacher.

In the next MM lines describe the relations: jj-th line contains two integers sjs_j, tjt_j (1sjN11 \le s_j \le N-1, 1tjN1 \le t_j \le N) indicating that sjs_j-th student can give flowers to the tjt_j-th teacher. It is guaranteed that all pairs are different.

Output Format

If it is impossible to give all teachers the same number of flowers (N1N-1 flowers), print a single number 1-1 in the first line.

Otherwise, your program should output MM lines. In jj-th line, there should be a single integer denoting the number of flowers which sjs_j-th student gave to tjt_j-th teacher.

If there are multiple possible answers, you can output any of them.

6 12
1 3
1 4
1 5
2 2
2 4
3 1
3 3
4 1
4 2
4 4
5 4
5 6
1
0
5
5
1
2
4
3
0
3
1
5
6 12
1 2
1 3
1 4
2 2
2 4
3 1
3 3
4 1
4 2
4 4
5 5
5 6
-1