from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
def solve():
numY = 2*10**5
#numY = 5
N, Q = map(int, input().split())
PQs = [[] for _ in range(numY)]
bels = [-1] * N
rates = [0] * N
for no in range(N):
A, B = map(int, input().split())
B -= 1
heappush(PQs[B], (-A, no))
bels[no] = B
rates[no] = A
PQMAX = []
for y in range(numY):
if PQs[y]:
m, no = PQs[y][0]
heappush(PQMAX, (-m, y, -1))
tmUpdates = [-1] * numY
anss = []
for tm in range(Q):
C, D = map(int, input().split())
C, D = C-1, D-1
# 転園元
bel = bels[C]
rate, no = PQs[bel][0]
if no == C:
while 1:
heappop(PQs[bel])
if not PQs[bel]:
tmUpdates[bel] = tm
break
rate, no = PQs[bel][0]
if no != C and bels[no] == bel:
heappush(PQMAX, (-rate, bel, tm))
tmUpdates[bel] = tm
break
# 転園先
if PQs[D]:
rate0, no = PQs[D][0]
heappush(PQs[D], (-rates[C], C))
rate, no = PQs[D][0]
if rate < rate0:
heappush(PQMAX, (-rate, D, tm))
tmUpdates[D] = tm
else:
rate = rates[C]
heappush(PQs[D], (-rate, C))
heappush(PQMAX, (rate, D, tm))
tmUpdates[D] = tm
# min
rate, y, tm = PQMAX[0]
while tm < tmUpdates[y]:
heappop(PQMAX)
rate, y, tm = PQMAX[0]
anss.append(rate)
bels[C] = D
print('\n'.join(map(str, anss)))
solve()