#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 15, lg = 20;
int mod = 1e9 + 7;
int inf = 1e9;
bool badhigh[N];
int main() {
FIO
int n, m;
cin >> n >> m;
vector<int> v(n);
for (auto &it:v)cin >> it;
sort(v.begin(), v.end());
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
badhigh[y] = 1;
}
ll ans = 0, co = 0;
for (int h = v.back(); h > 0; h--) {
while (v.size() && v.back() >= h)co++, v.pop_back();
if (badhigh[h])continue;
ans += co;
}
cout << ans << endl;
return 0;
}
Copy