#include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for(i = 0; i < n; i++) #define int long long using namespace std; int n, q; int a[100000]; int sa[100000]; int x, y; signed main() { int i; cin >> n >> q; rep(i, n) { cin >> a[i]; a[i] = -a[i]; } rep(i, n) sa[i] = a[i]; sort(sa, sa + n); rep(i, q) { cin >> x >> y; x--; y--; int l = upper_bound(sa, sa + n, a[x]) - sa; int r = lower_bound(sa, sa + n, a[y]) - sa; cout << max(0LL, r - l) << endl; } return 0; }