#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 200010;
int n , m , h[N];
int main(){
scanf("%d%d",&n,&m);
for(int i = 0 ;i < n;i++){
scanf("%d",&h[i]);
}
sort(h , h + n);
int mx = h[n - 1];
vector< int > v;
for(int a , b , i = 0 ;i < m;i++){
scanf("%d%d",&a,&b);
v.push_back(b);
}
sort(v.begin(),v.end());
int j = 0 , k = 0;
long long ans =0;
for(int idx , i = 1 ;i <= mx;i++){
while(j < m && v[j] < i) j++;
while(k < n && h[k] < i) k++;
if(j < m && v[j] == i) continue;
ans += n - k;
}
cout << ans << endl;
return 0;
}
Copy