#include <iostream>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, Q, A[1 << 18];

int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
	sort(A + 1, A + N + 1);

	for (int i = 1; i <= Q; i++) {
		int cl, cr; scanf("%d%d", &cl, &cr);
		int pos1 = lower_bound(A + 1, A + N + 1, cl) - A;
		int pos2 = lower_bound(A + 1, A + N + 1, cr + 1) - A;
		printf("%d\n", pos2 - pos1);
	}
	return 0;
}
