NOIP2012 借教室 Time:3s Memory:50M AC:28% Submit:11

样例1

样例输入1

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

样例输出1

-1
2