#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri(), q = ri();
	int a[n];
	for (auto &i : a) i = ri();
	std::sort(a, a + n);
	for (int i = 0; i < q; i++) {
		int l = ri(), r = ri();
		std::cout << std::upper_bound(a, a + n, r) - std::lower_bound(a, a + n, l) << std::endl;
	}
	return 0;
}



