#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define haimu(x) (1<<(x))
#define nl '\n'
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q;
    cin >> n >> q;
    vector <int> a(n+1);
    int k=log2(n)+1;
    vector<vector<int>> st(n+1,vector<int>(k));
    for (int i=1;i<=n;i++) {
        cin >> a[i];
        st[i][0]=a[i];
    }
    for (int j=1;(haimu (j))<=n;j++) {
        for (int i=1;i+(haimu (j))-1<=n;i++) {
            st[i][j]=max(st[i][j-1],st[i+(haimu (j-1))][j-1]);
        }
    }
    int cnt=0;
    while (q--) {
        int l,r;
        cin >> l >> r;
        int k=floor(log2(r-l+1));
        if (max(st[l][k],st[r-(haimu(k))+1][k])==a[l]) cnt++;
    }
    cout << cnt;
    return 0;
}