#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
int w[200001], tmp[200001];
pair<int, pair<int, bool> > ev[400000];
int main(){
int n, m;
scanf("%d%d", &n, &m);
f(i, 1, n + 1)scanf("%d", tmp + i);
int j = 1;
while (tmp[j])++j;
if (++j == n + 1)j = 1;
f(i, 1, n + 1)w[i] = tmp[(i + j - 2) % n + 1];
f(i, 0, m){
int l, r;
scanf("%d%d", &l, &r);
if ((l -= j - 1) <= 0)l += n;
if ((r -= j - 1) <= 0)r += n;
if (l > r)swap(l, r);
ev[i << 1] = make_pair(l, make_pair(l, false));
ev[i << 1 | 1] = make_pair(r, make_pair(l, true));
}
sort(ev, ev + (m << 1));
deque<pair<ll, int> > q1, q2;
q1.push_back(make_pair(0, 1));
q2.push_back(make_pair(0, 1));
m <<= 1;
j = 0;
int a = 1, b = 1;
f(i, 1, n){
while (j < m && ev[j].first <= i){
if (ev[j].second.second)b = max(b, ev[j].second.first + 1);
else a = max(a, ev[j].second.first + 1);
++j;
}
while (!q1.empty() && q1.front().second < a)q1.pop_front();
while (q2.front().second < b)q2.pop_front();
ll an = w[i] + q2.front().first;
if (!q1.empty())an = min(an, q1.front().first);
while (!q1.empty() && q1.back().first >= an)q1.pop_back();
q1.push_back(make_pair(an, i + 1));
while (!q2.empty() && q2.back().first >= an)q2.pop_back();
q2.push_back(make_pair(an, i + 1));
}
printf("%lld\n", q2.back().first);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZihpLCB4LCBuKSBmb3IoaW50IGkgPSB4OyBpIDwgKGludCkobik7ICsraSkKCmludCB3WzIwMDAwMV0sIHRtcFsyMDAwMDFdOwpwYWlyPGludCwgcGFpcjxpbnQsIGJvb2w+ID4gZXZbNDAwMDAwXTsKCmludCBtYWluKCl7CglpbnQgbiwgbTsKCXNjYW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