class segmentTree: unit = -1 * 10 ** 10 def __init__(self, dataPieces, data): self.dataPieces = dataPieces self.data = data cellnumpow = 0 while not(2 ** (cellnumpow - 1) < dataPieces <= 2 ** cellnumpow): cellnumpow += 1 self.cnp = cellnumpow self.contena = [ segmentTree.unit for _ in range(2 ** (cellnumpow + 1))] for i in range(dataPieces): self.contena[2 ** cellnumpow + i] = data[i] cellnumpow -= 1 while cellnumpow >= 0: c = 2 ** cellnumpow for j in range(c): self.contena[c + j] = max(self.contena[2 * (c + j)],self.contena[2 * (c + j) + 1]) cellnumpow -= 1 def update(self, n: int, x: int): cnp = self.cnp now = 2 ** cnp + (n - 1) self.contena[now] = x while now > 1: if now % 2 == 0: now //= 2 else: now -= 1 now //= 2 self.contena[now] = max(self.contena[2 * now], self.contena[2 * now + 1]) def search(self, c: int , X: int): cnp = self.cnp now = 1 if self.contena[1] <= X: return -1 elif c == 1: while now < 2 ** cnp: if self.contena[2 * now] <= X and self.contena[2 * now + 1] > X: now = 2 * now + 1 else: now = 2 * now elif c == 2: while now < 2 ** cnp: if self.contena[2 * now] > X and self.contena[2 * now + 1] <= X: now = 2 * now else: now = 2 * now + 1 return now - 2 ** cnp + 1 N, Q = map(int,input().split()) A = list(map(int,input().split())) query = [] for _ in range(Q): query.append(list(map(int,input().split()))) seg = segmentTree(N, A) for i in range(Q): a = seg.search(query[i][0], query[i][1]) print(a) if a == -1: pass else: seg.update(a, segmentTree.unit)