Mooo Moo

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John forgot how many cows he owns. He placed microphones in NN fields along a road to estimate cow counts from mooing volume.

Breed ii moos at volume V(i)V(i). Wind blows left to right: if a field's total volume is XX, the next field gains max(0,X1)max(0, X-1) from carryover.

Given recorded total volumes, find the minimum possible number of cows, or 1-1 if impossible.

Input

Line 1: NN, BB.

Next BB lines: V(i)V(i).

Next NN lines: recorded volume in each field.

Output

Minimum number of cows, or 1-1.