#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

int table[SIZE];

int main(){

	int N,num_query;
	scanf("%d %d",&N,&num_query);

	for(int i = 0; i < N; i++){

		scanf("%d",&table[i]);
	}

	sort(table,table+N);

	int left,right;
	int LEFT,RIGHT;
	int L,R,mid;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d",&left,&right);

		L = 0,R = N-1,mid = (L+R)/2;
		LEFT = N;

		while(L <= R){

			if(table[mid] >= left){

				LEFT = mid;
				R = mid-1;

			}else{

				L = mid+1;
			}
			mid = (L+R)/2;
		}

		if(LEFT == N)continue;

		L = 0, R = N-1,mid = (L+R)/2;
		RIGHT = -1;

		while(L <= R){

			if(table[mid] <= right){

				RIGHT = mid;
				L = mid+1;
			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}

		printf("%d\n",RIGHT-LEFT+1);
	}

	return 0;
}

