n,a=map(int,input().split()) x=list(map(int,input().split())) x.sort() q=[] for i in range(n): q+=[(x[i],1,i)] t=int(input()) for i in range(t): l,r=map(int,input().split()) q+=[(l,0,i)] q+=[(r,2,i)] q.sort() ans=[-1]*n v=[0]*t from heapq import heappush,heappop p=[] for x,y,z in q: if y==0: heappush(p,-z) v[z]=1 if y==1: while len(p)>0 and v[-p[0]]==0: heappop(p) if len(p)>0: ans[z]=-p[0]+1 if y==2: v[z]=0 print(*ans,sep="\n")