Buses#1389

Buses

1 segundo
128 megabytes
Muy fácil (≈850)

Between some villages of the Vasyuki district, there are bus routes. As the passenger traffic is not very large, the buses run only a few times a day.

Maria wants to get from the village to the village as soon as possible (it is assumed that at time she is in the village ).

Entrada

First, you are given the total number of villages (1 \leq n \leq 100), and , then the number of bus lines (0 \leq r \leq 10000). Then the description of bus trips is given. Each route is described by the number of the starting village, the departure time, the destination village, and the arrival time (all times are integers from to ). If at time the passenger arrives in a village, they can leave it at any time starting from .

Salida

Print the minimum time when Maria can reach village . If it is not possible to get from to using the given bus trips, output .

Ejemplos

Ejemplo 1

Loading
Loading