#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)9e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
if (!(cin >> n >> m)) return 0;
vector<ll> a(n+1);
for (int i = 1; i <= n; ++i) cin >> a[i];
vector<int> L(m), R(m);
for (int i = 0; i < m; ++i) cin >> L[i] >> R[i];
// prefix sum
vector<ll> P(n+1, 0);
for (int i = 1; i <= n; ++i) P[i] = P[i-1] + a[i];
// bestVal[r][i] = minimal sum of a[i..j] for j in [i, R[r]]
// bestEnd[r][i] = index j giving that minimum. valid only for i in [L[r], R[r]]
vector<vector<ll>> bestVal(m, vector<ll>(n+2, INF));
vector<vector<int>> bestEnd(m, vector<int>(n+2, -1));
for (int r = 0; r < m; ++r) {
int l = L[r], rr = R[r];
// compute suffix minimum of P[j] over j in [l..rr]
ll curMin = INF;
int curIdx = -1;
for (int j = rr; j >= l; --j) {
if (P[j] <= curMin) {
curMin = P[j];
curIdx = j;
}
// for start = j, minimal P[j'] for j' >= j is curMin at curIdx
// sum(a[j..curIdx]) = curMin - P[j-1]
bestVal[r][j] = curMin - P[j-1];
bestEnd[r][j] = curIdx;
}
}
int MSK = 1 << m;
// dp[pos][mask] : minimal total when we've processed positions < pos, and used rounds = mask
// pos ranges 1..n+1
vector<vector<ll>> dp(n+2, vector<ll>(MSK, INF));
dp[1][0] = 0;
for (int pos = 1; pos <= n; ++pos) {
for (int mask = 0; mask < MSK; ++mask) {
ll cur = dp[pos][mask];
if (cur == INF) continue;
// option 1: skip pos (no segment starts at pos)
if (dp[pos+1][mask] > cur) dp[pos+1][mask] = cur;
// option 2: try to start a segment at pos assigned to some unused round r
for (int r = 0; r < m; ++r) {
if (mask & (1 << r)) continue; // already used
if (pos < L[r] || pos > R[r]) continue; // cannot start here
ll val = bestVal[r][pos];
int endp = bestEnd[r][pos];
if (endp == -1) continue; // shouldn't happen but safe-guard
int nmask = mask | (1 << r);
int nextPos = endp + 1;
if (dp[nextPos][nmask] > cur + val) dp[nextPos][nmask] = cur + val;
}
}
}
// also allow reaching n+1 by skipping from n+1? Already dp updated until n+1.
ll ans = INF;
for (int mask = 0; mask < MSK; ++mask) {
ans = min(ans, dp[n+1][mask]);
}
// print minimal S
cout << ans << '\n';
return 0;
}