n, q = map(int, input().split()) a = list(map(int, input().split())) #d = [0] * 100001 d = [0] * 100001 for i in a: d[i] = 1 for _ in [0]*q: x, y = map(int, input().split()) #if a[x-1] <= a[y-1]: # print(0) # continue cnt = 0 for i in range(a[x-1]-1, a[y-1], -1): cnt += d[i] print(cnt)