Optimal Milking

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John's new barn holds NN milking machines standing in a row, numbered 11 through NN from the left.

Machine ii extracts M(i)M(i) units of milk per day. The machines sit so close together that if machine ii runs on a given day, neither of its neighbors can run that day. A machine at either end has only one neighbor. Farmer John may choose a different set of machines to run on each day.

Farmer John wants the largest total amount of milk he can extract over DD days. At the start of each day he has time to service one machine, and that machine's daily output M(i)M(i) changes from that day onward. Given the list of daily changes, report the maximum total milk over the DD days. The answer can exceed a 32-bit integer.

1N400001 \le N \le 40000, 1M(i)1000001 \le M(i) \le 100000, and 1D500001 \le D \le 50000.

Input

The first line contains NN and DD.

Each of the next NN lines gives one initial value, with line ii holding M(i)M(i).

Each of the following DD lines contains two integers ii and mm. Line dd means Farmer John sets M(i)M(i) to mm at the start of day dd.

Output

Print the maximum total amount of milk Farmer John can produce over the DD days.

Hint

Suppose five machines start with outputs 1, 2, 3, 4, 5 and machine 5 drops to 2 on the morning of day one.

Day one is best at 2+4=62 + 4 = 6, and 1+3+21 + 3 + 2 reaches 6 as well. If machine 2 then rises to 7, day two is 7+4=117 + 4 = 11, and if machine 1 rises to 10, day three is 10+3+2=1510 + 3 + 2 = 15.