Bridge Transport

No attempts yetTime limit1sMemory limit128 MB

Problem

A train of railway cars attempts to cross a bridge. Each car is 10m long, but their weights may differ. The bridge is 40m long, so at most 4 cars can sit on it at any one time. The bridge cracks whenever the total weight of the cars currently on it exceeds a fixed weight limit. The cars are numbered from 1 to $N$ and cross the bridge in that order (car 1 immediately followed by car 2, immediately followed by car 3, and so on).

Find the largest $T$ such that cars $1 \dots T$, in order, can all be brought across the bridge.

Input

The first line contains the maximum weight $W$ ($1 \le W \le 100000$) that the bridge can hold at any one time. The second line contains the number of railway cars $N$ ($1 \le N \le 100000$) we wish to move across. Each of the next $N$ lines contains a positive integer $w_i$ ($1 \le w_i \le 100000$), the weight of the $i$-th car in the sequence.

Output

Output a single non-negative integer: the maximum number of railway cars that can be brought across the bridge in the given order.

Hint

Suppose the bridge can hold 100 and the cars weigh 50, 30, 10, 10, 40, 50 in order. The first four cars weigh $50 + 30 + 10 + 10 = 100$, which does not exceed the limit. Once the first car leaves and the fifth comes on, the total is $30 + 10 + 10 + 40 = 90$, still within the limit. However, the last four cars weigh $10 + 10 + 40 + 50 = 110$, which exceeds the limit and would crack the bridge. Therefore only the first 5 cars can cross.