F. Plane Seating Roulette
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
1
4 1
2
2
2
Output
1
Input
1
4 1
2
1
1
Output
2