#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> x(n + 1);
x[0] = make_pair(0, 0);
for(int i = 1; i <= n; i++){
cin >> x[i].first;
x[i].second = i;
}
sort(x.begin(), x.end());
vector<int> prefmin(n + 1), prefmax(n + 1);
for(int i = 0; i <= n; i++){
prefmin[i] = x[i].second;
prefmax[i] = x[i].second;
if(i > 0){
prefmin[i] = min(prefmin[i], prefmin[i - 1]);
prefmax[i] = max(prefmax[i], prefmax[i - 1]);
}
}
vector<int> sufmin(n + 1), sufmax(n + 1);
for(int i = n; i >= 0; i--){
sufmin[i] = x[i].second;
sufmax[i] = x[i].second;
if(i != n){
sufmin[i] = min(sufmin[i], sufmin[i + 1]);
sufmax[i] = max(sufmax[i], sufmax[i + 1]);
}
}
int ans = 0;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
bool can = 0;
if(a < b){
int pref = lower_bound(x.begin(), x.end(), make_pair(a, n + 1)) - x.begin() - 1;
int suf = lower_bound(x.begin(), x.end(), make_pair(b, -1)) - x.begin();
if(pref >= 0 && suf <= n && prefmin[pref] < sufmax[suf]){
can = 1;
}
}
else{
int pref = lower_bound(x.begin(), x.end(), make_pair(b, n + 1)) - x.begin() - 1;
int suf = lower_bound(x.begin(), x.end(), make_pair(a, -1)) - x.begin();
if(pref >= 0 && suf <= n && sufmin[suf] < prefmax[pref]){
can = 1;
}
}
if(can){
ans++;
}
}
cout << ans << endl;
return 0;
}