#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);
}