class segtree: def __init__(self,n): self.size=1 self.height=0 while self.size>h self.lazy[2*y]=max(self.lazy[y],self.lazy[2*y]) self.lazy[2*y+1]=max(self.lazy[y],self.lazy[2*y+1]) self.dat[y]=max(self.dat[y],self.lazy[y]) self.lazy[y]=-1 def bottom(self,x): x+=self.size while x>1: x//=2 self.dat[x]=max(max(self.dat[2*x],self.lazy[2*x]),max(self.dat[2*x+1],self.lazy[2*x+1])) N,ppp=map(int,input().split()) A=list(map(int,input().split())) B=set() for i in range(N): B.add(A[i]) B=list(B) B.sort() T={} for i in range(len(B)): T[B[i]]=i M=len(B) Z=segtree(M) K=int(input()) from bisect import bisect_left,bisect_right for t in range(1,K+1): l,r=map(int,input().split()) pos1=bisect_left(B,l) pos2=bisect_right(B,r) Z.propagate(pos1) Z.propagate(pos2-1) Z.lazyup(pos1,pos2,t) Z.bottom(pos1) Z.bottom(pos2-1) for i in range(N): pos=T[A[i]] Z.propagate(pos) ans=Z.querry(pos,pos+1) print(ans)