import sys input = sys.stdin.readline R, N = map(int, input().split()) A = list(map(int, input().split())) Q = int(input()) LR = [list(map(int, input().split())) for _ in range(Q)] cnt = [0 for _ in range(R)] for a in A: cnt[a] += 1 S = [0] for c in cnt: S.append(S[-1]+c) for l, r in LR: t = r-l+1 loop = t//R ans = loop*S[-1] ans += S[-1] - S[l%R] ans += S[(r+1)%R] print(ans)