#include <bits/stdc++.h>
#define ll long long
const int N = 1e6+5;
const ll mod = 998244353;
using namespace std;
int n,k;
vector<ll> a(N);
void solve()
{
cin >> n >> k;
ll op = 0;
ll ko = 0;
deque<ll> st;
for (int i=1;i<=n;i++)
{
cin >> a[i];
while (!st.empty())
{
if (st.back() <= a[i])
{
st.pop_back();
}else
{
break;
}
}
st.push_back(a[i]);
}
for (int i=1;i<=k;i++)
{
int l,r;
cin >> l >> r;
}
for (int i=2;i<=n;i++)
{
if (a[i] > ko)
{
op += a[i]-ko-1;
ko = a[i];
}
}
cout << op+n-1+st.front()-((int)st.size()-1) << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
solve();
}