PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000284. Theo dõi các đoạn đẹp (Tracking Segments)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Theo dõi các đoạn đẹp (Tracking Segments)

Tracking Segments

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An array of nn zeros has mm monitored intervals [li,ri][l_i,r_i], which may repeat. An interval is beautiful when its ones strictly outnumber its zeros. Change j sets axj=1a_{x_j}=1, with all positions xjx_j distinct. Find the first change after which any monitored interval is beautiful, or −1-1 if none ever is.

Input

First line: n,mn,m. The next m lines contain li,ril_i,r_i. The next line contains qq, followed by q lines with one xjx_j each.

Output

Print the first change number (1-based), or −1-1.

Subtasks

  • Subtask 1 (20 points): 1≤m≤n≤301\le m\le n\le30; 1≤li≤ri≤n1\le l_i\le r_i\le n; 1≤q≤n1\le q\le n; 1≤xj≤n1\le x_j\le n; xjx_j are pairwise distinct.
  • Subtask 2 (30 points): 1≤m≤n≤1051\le m\le n\le10^5; 1≤li=ri≤n1\le l_i=r_i\le n; 1≤q≤n1\le q\le n; 1≤xj≤n1\le x_j\le n; xjx_j are pairwise distinct.
  • Subtask 3 (50 points): 1≤m≤n≤1051\le m\le n\le10^5; 1≤li≤ri≤n1\le l_i\le r_i\le n; 1≤q≤n1\le q\le n; 1≤xj≤n1\le x_j\le n; xjx_j are pairwise distinct.

Examples

Input 1

5 2
1 5
2 4
4
1
5
3
2

Output 1

3

Explanation

After two changes [1,5] has two ones; after the third it has three ones and two zeros.

Input 2

4 2
1 1
4 4
2
2
3

Output 2

-1

Explanation

Neither monitored position changes.