program ex_2;
uses math;
var f:array[-3..40000] of longint;
m:array[1..40000] of longint;
d,n,i,k,l,j:longint;
total:int64;
begin
assign(input,'optmilk.in'); reset(input);
assign(output,'optmilk.out'); rewrite(output);
readln(n,d);
for i:=1 to n do
begin
readln(m[i]);
end;
total:=0;
for i:=1 to n do
begin
f[i]:=max(f[i-2],f[i-3])+m[i];
end;
for i:=1 to d do
begin
readln(k,l);
m[k]:=l;
for j:=k to n do
begin
f[j]:=max(f[j-2],f[j-3])+m[j];
end;
total:=total+max(f[n-1],f[n]);
end;
writeln(total);
close(input); close(output);
end.