#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  map<int, int> mp;
  map<int, int> num;
  int n, q; cin >> n >> q;
  for(int i=0;i<n;++i) {
    int a; cin >> a;
    mp[a]++;
  }

  vll su(SZ(mp)+1);
  int pos = 0;
  for(auto &e: mp) {
    num[e.first] = pos+1;
    su[pos+1] = su[pos] + e.second;
    pos++;
  }

  for(int i=0;i<q;++i) {
    int l, r; cin >> l >> r;
    auto it1 = mp.lower_bound(l);
    auto it2 = mp.upper_bound(r);
    //cout << it1->first << ":" << it2->first << endl;
    //cout << num[it1->first] << ":" << num[it2->first] << endl;
    if(it1 != mp.end() && it2 != mp.end()) cout << su[num[it2->first]-1] - su[num[it1->first]-1] << endl;
    else if(it1 != mp.end()) cout << su[SZ(mp)] - su[num[it1->first]-1] << endl;
    else cout << 0 << endl;
  }

}

