Luggage Screening
At an airport security checkpoint, a screener needs to find a specific bag from a conveyor belt of identical-looking luggage. Each bag has 5 property values that can be inspected: properties 0 through 4. The screener has a checklist of up to 5 property requirements that the target bag must satisfy.
Your task is to find which bag (by position on the belt) matches all the requirements, checking each bag in order from the front of the conveyor.
Input
The first line contains n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 5), the number of bags and the number of requirements.
The next n lines each contain 5 integers, the property values (0 to 10^9) of each bag in order.
The next k lines each contain two integers p and v (0 ≤ p ≤ 4, 0 ≤ v ≤ 10^9), specifying that property p must equal v.
Output
Print the 0-based index of the first bag that satisfies all k requirements. If no bag matches, print -1.
Notes
The solution checks each bag in order against all requirements, stopping at the first match. This is a straightforward linear scan where constraints help prune which bags to accept.