Bessie the cow is tired of the cold winter on her farm and plans to fly somewhere warmer for a vacation. Only one airline, Air Bovinia, is willing to sell tickets to cows, and its tickets have a slightly unusual structure.
Air Bovinia owns N planes. Each plane flies a fixed "route" made of two or more cities. For example, one plane might fly a route that starts at city 1, then goes to city 5, then city 2, and finally city 8. No city appears twice on the same route. If Bessie decides to use a route, she can board at any city on that route and get off at any city that comes later on the same route. She does not have to board at the first city, and she does not have to get off at the last city. Each route has a fixed cost, and she pays that cost in full if she uses any part of the route, no matter how many cities she passes.
Bessie wants the cheapest way to get from her farm in city A to her destination, city B. She does not want a complicated itinerary, so she uses only one route. Find the minimum cost she has to pay.
The first line contains A, B, and N, separated by spaces. (1≤N≤500, 1≤A,B≤10000, A=B)
The next 2N lines describe the routes, two lines per route. The first line of a route contains the cost of using that route (an integer from 1 to 1000) and the number of cities on the route (an integer from 1 to 500). The second line lists the cities on that route in flight order. Each city is an integer from 1 to 10000.
Print the minimum cost of a single route Bessie can use to travel from city A to city B. If there is no such route, print -1.
Even when using two routes in sequence would be cheaper, Bessie may use only one route. Only a route on which A appears before B counts as a candidate.