import bisect def main(): n, q = map(int, input().split()) *a, = map(int, input().split()) b = sorted(a) for i in range(q): y, x = map(int, input().split()) print(max(0, bisect.bisect_left( b, a[y-1]) - bisect.bisect_right(b, a[x-1]))) if __name__ == '__main__': main()