Rain
A raindrop falls straight down from a significant height to the ground. During its descent, it may encounter obstacles that change its path.
We will examine a two-dimensional version of this scenario on a plane. The obstacles are inclined line segments that do not intersect, and the raindrop is considered to be a point. The drop falls vertically from a point above all obstacles. If it touches a segment while falling, it slides along the segment until it reaches the lower end, from where it continues to fall vertically.
Write a program to calculate the coordinate X_0 of the drop's initial position above the ground, and determine the coordinate X where the drop ultimately lands on the ground (Y = 0).
Input
The input begins with two integers separated by a space on the first line: the coordinate X_0 of the drop's starting point (0 < X_0 < 10000) and the number of segment-obstacles N (0 ≤ N ≤ 100). This is followed by N lines, each containing four space-separated integers x_1 , y_1, x_2, y_2_ – the coordinates of the left and right endpoints of each segment-obstacle (all numbers are integers ranging from 0 to 10000, x_{1 } < x_2, y_{1 } ≠ y_2). The segments do not intersect or touch each other.
Output
Output a single integer: the coordinate X where the drop lands on the ground.