#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void magic(){
int n,m; cin>>n>>m;
int h[n];
for(int i = 0 ; i<n ; i++){
cin>>h[i];
}
sort(h,h+n);
int N = h[n-1];
bool floors[N] = {};
for(int i = 0 ; i<m ; i++){
int a , b ; cin>>a>>b;
floors[b] = 1;
}
ll ans = 0 ;
for(int i = N ; i>0 ; i--){
int x = n - (lower_bound(h,h+n,i) - h);
if(!floors[i]){ans+=x;}
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie();
std::cout.tie();
int t = 1; //cin>>t;
while (t--)
magic();
}
Copy