#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> adjList;
typedef pair<int, pair<int, int>> iii;
typedef vector<unsigned int> vui;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vi vm;
typedef vector<vm> Mat;
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
// freopen("outofplace.in", "r", stdin);
// freopen("outofplace.out", "w", stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;
int n, m; cin >> n >> m;
vi h(n);
for (int i = 0; i < n; ++i) cin >> h[i];
vi acc(2e5 + 5);
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
acc[b] = 1;
}
for (int i = 1; i < sz(acc); ++i) {
acc[i] += acc[i - 1];
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += h[i] - acc[h[i]];
}
cout << ans << '\n';
return 0;
}
Copy