A service lift in a building can stop at floors 0 through maxFloor. It begins at a given starting floor and receives a sequence of signed move commands. Each command is an integer delta: a positive value goes up, a negative value goes down. The lift may not pass the ends of its shaft, so after each command its floor is limited to the range [0, maxFloor] - if a command would take it below 0 it stops at floor 0, and if it would take it above maxFloor it stops at maxFloor.
Input format
Line 1: two integers maxFloor and start (with 0 <= start <= maxFloor).
Line 2: an integer n, the number of commands.
Line 3: n space-separated integers, the deltas in order.
Output format
A single integer: the lift's final floor.
Constraints
- 0 <= maxFloor <= 1000000
- 0 <= start <= maxFloor
- 1 <= n <= 100000
- -1000000 <= each delta <= 1000000