#!/bin/python3 # https://www.hackerrank.com/contests/w34/challenges/same-occurrence import sys from collections import Counter def query(x, y, arr): l = len(arr) counter = 0 for i in range(l, 0, -1): for j in range(0, i): c = Counter(arr[j:i]) if x in c and y in c and c[x] == c[y]: counter += 1 elif x not in c and y not in c: counter += 1 return counter if __name__ == "__main__": n, q = input().strip().split(' ') n, q = [int(n), int(q)] arr = list(map(int, input().strip().split(' '))) for a0 in range(q): x, y = input().strip().split(' ') x, y = [int(x), int(y)] print(query(x, y, arr))