Zane the wizard is going to perform a magic show shuffling the cups.

There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.

The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = u_{i} and x = v_{i}. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.

Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation. [Image] 

Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.


-----Input-----

The first line contains three integers n, m, and k (2 ≤ n ≤ 10^6, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·10^5) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

The second line contains m distinct integers h_1, h_2, ..., h_{m} (1 ≤ h_{i} ≤ n) — the positions along the x-axis where there is a hole on the table.

Each of the next k lines contains two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}) — the positions of the cups to be swapped.


-----Output-----

Print one integer — the final position along the x-axis of the bone.


-----Examples-----
Input
7 3 4
3 4 6
1 2
2 5
5 7
7 1

Output
1
Input
5 1 2
2
1 2
2 4

Output
2


-----Note-----

In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively.

In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
from collections import *
(n, m, k) = map(int, input().split())
d = defaultdict(int)
for i in map(int, input().split()):
	d[i] += 1
l = [0] * (n + 1)
l[1] = 1
for i in range(k):
	(u, v) = map(int, input().split())
	if l[u] and u in d:
		print(u)
		exit(0)
	elif (l[u] or l[v]) and v in d:
		print(v)
		exit(0)
	else:
		(l[u], l[v]) = (l[v], l[u])
print(l.index(1))


(n, m, k) = map(int, input().split())
A = set(map(int, input().split()))
pre = 1
for i in range(k):
	(x, y) = map(int, input().split())
	if pre not in [x, y]:
		continue
	if pre == x and x in A:
		print(x)
		break
	elif pre == y and y in A:
		print(y)
		break
	pre = y if y != pre else x
else:
	print(pre)


(n, m, k) = map(int, input().split())
m1 = set(map(int, input().split()))
i = 1
for j in range(k):
	(u, v) = map(int, input().split())
	if i in m1:
		break
	if i == u:
		i = v
	elif i == v:
		i = u
print(i)


from sys import stdin
from collections import Counter
(a, b, c) = map(int, stdin.readline().split())
k = [0] * (a + 1)
k[1] = 1
d = Counter(list(map(int, stdin.readline().split())))
if d[1]:
	exit(print(1))
for _ in ' ' * c:
	(e, f) = map(int, stdin.readline().split())
	(k[e], k[f]) = (k[f], k[e])
	if k[e] == 1 and d[e]:
		exit(print(e))
	if k[f] == 1 and d[f]:
		exit(print(f))
print(k.index(1))


(n, m, k) = list(map(int, input().split()))
otv = set(input().split())
x = '1'
for _ in range(k):
	if x in otv:
		break
	(o, p) = input().split()
	if x == o:
		x = p
	elif x == p:
		x = o
print(x)


(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
d = [0] * (n + 1)
for i in range(m):
	d[h[i]] = 1
pos = 1
for i in range(k):
	(u, v) = map(int, input().split())
	if d[pos] == 1:
		print(pos)
		exit()
	if u == pos:
		pos = v
	elif v == pos:
		pos = u
print(pos)


(n, m, k) = map(int, input().split())
holes = set(map(int, input().split()))
moves = [map(int, input().split()) for _ in range(k)]
ball = 1
for (a, b) in moves:
	if ball in holes:
		break
	if a == ball:
		ball = b
	elif b == ball:
		ball = a
print(ball)


from sys import stdin, stdout
write = stdout.write
(n, m, k) = map(int, stdin.readline().split())
holes = {int(i): 0 for i in stdin.readline().split()}
poss = [False] * (n + 1)
poss[1] = True
ans = 1
trap = False
mAns = 1
for i in range(k):
	(x, y) = map(int, stdin.readline().split())
	if poss[x]:
		if x in holes:
			trap = True
			mAns = x
		else:
			poss[x] = False
			poss[y] = True
			ans = y
	elif poss[y]:
		if y in holes:
			trap = True
			mAns = y
		else:
			poss[y] = False
			poss[x] = True
			ans = x
if trap:
	write(str(mAns) + '\n')
else:
	write(str(ans) + '\n')


R = lambda : map(int, input().split())
(n, m, k) = R()
d = set(R())
pos = 1
for _ in range(k):
	(u, v) = R()
	if pos in d:
		break
	if pos == u:
		pos = v
	elif pos == v:
		pos = u
print(pos)


from sys import stdin

def binary_search(data, val):
	if val > data[-1] or val < data[0]:
		return [-1, -2]
	high_index = len(data) - 1
	low_index = 0
	while high_index > low_index:
		index = (high_index + low_index) // 2
		sub = data[index]
		if data[low_index] == val:
			return [low_index, low_index]
		elif sub == val:
			return [index, index]
		elif data[high_index] == val:
			return [high_index, high_index]
		elif sub > val:
			if high_index == index:
				return sorted([high_index, low_index])
			high_index = index
		else:
			if low_index == index:
				return sorted([high_index, low_index])
			low_index = index
	return sorted([high_index, low_index])
(n, m, k) = map(int, stdin.readline().rstrip().split(' '))
l = list(map(int, stdin.readline().rstrip().split(' ')))
l.sort()
hole = False
s = 1
for i in range(k):
	(f, to) = map(int, stdin.readline().rstrip().split(' '))
	if s == f and (not hole):
		s = to
		x = binary_search(l, s)
		if x[0] == x[1]:
			hole = True
	elif s == to and (not hole):
		s = f
		x = binary_search(l, s)
		if x[0] == x[1]:
			hole = True
if l[0] == 1:
	print(1)
else:
	print(s)


def solver():
	(number_of_cups, number_of_holes, number_of_swaps) = map(int, input().split())
	holes = set(map(int, input().split()))
	bone_position = 1
	if bone_position not in holes:
		for _ in range(number_of_swaps):
			(cup1, cup2) = map(int, input().split())
			if cup1 == bone_position:
				bone_position = cup2
			elif cup2 == bone_position:
				bone_position = cup1
			if bone_position in holes:
				break
	print(bone_position)
solver()


(n, m, k) = map(int, input().split())
s = set()
for n in list(map(int, input().split())):
	s.add(n)
b = 1
for _ in range(k):
	if b in s:
		print(b)
		quit()
	(x1, x2) = map(int, input().split())
	if x1 == b:
		b = x2
	elif x2 == b:
		b = x1
print(b)


(n, m, k) = map(int, input().split())
h = set((int(x) for x in input().split()))
b = 1
In = []
for i in range(k):
	(u, v) = map(int, input().split())
	p = u
	u = v
	v = p
	if b in h:
		In.append(b)
		break
	if u == b:
		b = v
	elif v == b:
		b = u
if In == []:
	print(b)
else:
	print(In[0])


(n, m, k) = list(map(int, input().split()))
h = list(map(int, input().split()))
isLunka = []
j = 0
for i in range(0, n + 1):
	isLunka.append(0)
for i in range(len(h)):
	isLunka[h[i]] = 1
out = 0
x = 1
for i in range(k):
	(u, v) = list(map(int, input().split()))
	if x == u and isLunka[u]:
		out = u
		break
	if x == v and isLunka[v]:
		out = v
		break
	if x == u:
		x = v
	elif x == v:
		x = u
else:
	out = x
print(out)


(n, m, k) = [int(i) for i in input().split()]
h = set((int(i) - 1 for i in input().split()))
x = 0
if x not in h:
	for i in range(k):
		item = [int(i) - 1 for i in input().split()]
		if x == item[0]:
			x = item[1]
		elif x == item[1]:
			x = item[0]
		if x in h:
			break
print(x + 1)


(n, m, k) = [int(n) for n in input().split()]
holes = set([int(n) for n in input().split()])
bonePosition = [1]
for num in range(k):
	(first, second) = [int(n) for n in input().split()]
	if len(set(bonePosition) & holes) > 0:
		print(bonePosition[0])
		quit()
	if first == bonePosition[0]:
		if second < 1 or second > n:
			continue
		bonePosition[0] = second
	elif second == bonePosition[0]:
		if first < 1 or first > n:
			continue
		bonePosition[0] = first
print(bonePosition[0])


(n, k, t) = map(int, input().split())
ss = [0] * 10000009
s = list(map(int, input().split()))
for i in s:
	ss[i - 1] = 1
s1 = 1
f = 0
for i in range(t):
	(a, b) = map(int, input().split())
	if ss[s1 - 1] == 1 and f == 0:
		f = 1
		print(s1)
	if a == s1 or b == s1:
		if a == s1:
			s1 = b
		else:
			s1 = a
if f == 0:
	print(s1)


import sys, re, array, math, functools
input = lambda : sys.stdin.readline()

@functools.lru_cache(maxsize=10000)
def Main():
	(n, m, k) = map(int, input().split())
	H = set(list(map(int, input().split())))
	ans = 1
	if ans not in H:
		for i in range(k):
			(x, y) = map(int, input().split())
			if ans == x:
				ans = y
			elif ans == y:
				ans = x
			if ans in H:
				break
	print(ans)
Main()


(n, m, k) = [int(x) for x in input().split()]
h = set([int(x) for x in input().split()])
bone = 1
for i in range(k):
	if bone in h:
		break
	(a, b) = [int(x) for x in input().split()]
	if a == bone:
		bone = b
	elif b == bone:
		bone = a
print(bone)


(n, m, k) = [int(x) for x in input().split()]
holes_pos = [int(x) for x in input().split()]
holes = [0] * (n + 1)
for pos in holes_pos:
	holes[pos] = 1
pos = 1
for i in range(k):
	if holes[pos] == 1:
		break
	(a, b) = [int(x) for x in input().split()]
	if pos == a:
		pos = b
	elif pos == b:
		pos = a
print(pos)


(n, m, k) = map(int, input().split())
holes = set(map(int, input().split()))
ans = 1
swaps = []
for i in range(k):
	swaps = list(map(int, input().split()))
	if ans in holes:
		continue
	elif ans == swaps[0]:
		ans = swaps[1]
	elif ans == swaps[1]:
		ans = swaps[0]
print(ans)


import os
LOCAL_PC = 'n1amr' in os.path.expanduser('~')

def process_file(in_name, out_name):
	with open(in_name, 'r') as fin:
		with open(out_name, 'w') as fout:

			def read():
				return fin.readline().rstrip('\n')

			def write(*args, sep='\n'):
				fout.write(' '.join(map(str, args)) + sep)
			t = int(fin.readline())
			for i in range(t):
				read()
				write('Case #{T}: '.format(T=i + 1), sep='')
				solve(read, write)

def process_stdio():

	def read():
		return input()

	def write(*args, sep='\n'):
		print(*args, sep=sep)
	solve(read, write)

def solve(input, print):
	(n, m, k) = map(int, input().split())
	holes = set(map(lambda x: int(x) - 1, input().split()))
	bone = 0
	done = 0 in holes
	for i in range(k):
		(a, b) = map(lambda x: int(x) - 1, input().split())
		if done:
			continue
		if bone in [a, b]:
			bone = a if bone == b else b
		if bone in holes:
			done = True
	print(bone + 1)
if LOCAL_PC:
	in_name = __file__[:-3] + '.in'
	out_name = __file__[:-3] + '.out'
	process_file(in_name, out_name)
else:
	process_stdio()


inp = lambda : map(int, input().split())
(n, m, k) = inp()
f = [False] * (n + 1)
for i in inp():
	f[i] = True
current = 1
for i in range(k):
	(x, y) = inp()
	if f[current]:
		break
	if x == current:
		current = y
	elif y == current:
		current = x
print(current)


(n, m, k) = [int(x) for x in input().split()]
holes = [0 for x in range(n + 1)]
for x in input().split():
	holes[int(x)] = 1
bone = 1
wyn = 0
if holes[1] == 1:
	wyn = 1
u = [0 for x in range(k)]
v = [0 for x in range(k)]
for i in range(k):
	(u[i], v[i]) = [int(x) for x in input().split()]
for i in range(k):
	if u[i] == bone:
		bone = v[i]
	elif v[i] == bone:
		bone = u[i]
	if holes[bone] == 1 and wyn == 0:
		wyn = bone
if wyn == 0:
	print(bone)
else:
	print(wyn)


(n, m, k) = list(map(int, input().split()))
holes = set(list(map(int, input().split())))
bone_pos = 1
flag = True
for i in range(k):
	if bone_pos in holes:
		print(bone_pos)
		flag = False
		break
	(from_pos, to_pos) = list(map(int, input().split()))
	if from_pos == bone_pos:
		bone_pos = to_pos
	elif to_pos == bone_pos:
		bone_pos = from_pos
if flag:
	print(bone_pos)


(n, m, k) = map(int, input().split())
h = set(map(int, input().split()))
x = 1
for i in range(0, k):
	if x in h:
		break
	(u, v) = map(int, input().split())
	if x == u:
		x = v
	elif x == v:
		x = u
print(x)


(n, m, k) = list(map(int, input().split(' ')))
hs = list(map(int, input().split(' ')))
holes = set(hs)
pos = 1
for i in range(k):
	if pos in holes:
		break
	(u, v) = list(map(int, input().split(' ')))
	if pos == u:
		pos = v
	elif pos == v:
		pos = u
print(pos)


(n, m, k) = map(int, input().split())
holes = set(input().split())
pos = 1
for i in range(k):
	(x1, x2) = map(int, input().split())
	if str(pos) in holes:
		break
	if x1 == pos:
		pos = x2
	elif x2 == pos:
		pos = x1
print(pos)


(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
check = [0] * (n + 1)
for i in h:
	check[i] = 1
bone = 1
for _ in range(k):
	if check[bone]:
		break
	(u, v) = map(int, input().split())
	if bone == u:
		bone = v
	elif bone == v:
		bone = u
print(bone)


from sys import stdin, stdout

def ri():
	return list(map(int, stdin.readline().split()))
(n, m, k) = ri()
h = [0 for i in range(n + 1)]
hh = list(ri())
for i in range(m):
	h[hh[i]] = 1
p = 1
for i in range(k):
	if h[p] == 1:
		print(p)
		return
	(a, b) = ri()
	if p in [a, b]:
		if a == p:
			p = b
		else:
			p = a
print(p)


x = input().split(' ')
y = input().split(' ')
x = list(map(int, x))
y = list(map(int, y))
a = [True] * x[0]
pair = []
for i in range(len(y)):
	a[y[i] - 1] = False
for i in range(x[2]):
	z = input().split(' ')
	z = list(map(int, z))
	pair.append(z)
if a[0] == False:
	print(1)
else:
	cur = 1
	for i in range(len(pair)):
		if pair[i][0] == cur:
			cur = pair[i][1]
			if a[cur - 1] == False:
				break
		elif pair[i][1] == cur:
			cur = pair[i][0]
			if a[cur - 1] == False:
				break
	print(cur)


import sys
inp = sys.stdin.readline
(n, _, k) = map(int, inp().split())
st = set(map(int, inp().split()))
pos = 1
if 1 in st:
	print(1)
	exit()
for i in range(k):
	(a, b) = map(int, inp().split())
	if a == pos:
		pos = b
	elif b == pos:
		pos = a
	if pos in st:
		print(pos)
		exit()
print(pos)


def solve():
	(n, m, k) = map(int, input().split())
	h = set(map(int, input().split()))
	pos = 1
	for i in range(k):
		(u, v) = map(int, input().split())
		if pos != u:
			(u, v) = (v, u)
		if pos == u:
			if u not in h:
				pos = v
	print(pos)
solve()


(n, m, k) = map(int, input().split())
o = set(map(int, input().split()))
pos = 1
if pos in o:
	print(pos)
	exit()
for _ in range(k):
	(x, y) = map(int, input().split())
	if x == pos:
		pos = y
	elif y == pos:
		pos = x
	if pos in o:
		break
print(pos)


inp = input()
(n, m, k) = map(int, inp.split())
holes = set(input().split())
bone = '1'
for i in range(k):
	if bone in holes:
		break
	(u, v) = input().split()
	if bone == u:
		bone = v
	elif bone == v:
		bone = u
print(bone)


(n, m, k) = map(int, input().split())
h = set(map(int, input().split()))
answer = 1
if answer in h:
	print(answer)
else:
	for i in range(k):
		(u, v) = map(int, input().split())
		if u == answer:
			answer = v
		elif v == answer:
			answer = u
		else:
			continue
		if answer in h:
			break
	print(answer)


(n, m, k) = (int(x) for x in input().split())
h = set((int(x) for x in input().split()))
cur_pos = 1
for _ in range(k):
	[u, v] = [int(x) for x in input().split()]
	if cur_pos in h:
		break
	if cur_pos == u:
		cur_pos = v
	elif cur_pos == v:
		cur_pos = u
print(cur_pos)


(_, _, k) = input().split()
holes = dict(((int(x), True) for x in input().split()))
pos = 1
for i in range(int(k)):
	if holes.get(pos):
		break
	(x1, x2) = map(int, input().split())
	if not x1 ^ pos:
		pos = x2
	elif not x2 ^ pos:
		pos = x1
print(pos)


from sys import stdin
(n, m, k) = list(map(int, stdin.readline().split()))
holes = set(map(int, stdin.readline().split()))
pos = 1
if pos not in holes:
	for i in range(k):
		(u, v) = list(map(int, stdin.readline().split()))
		if u == pos:
			pos = v
			if pos in holes:
				break
		elif v == pos:
			pos = u
			if pos in holes:
				break
print(pos)


R = lambda : map(int, input().split())
(n, m, k) = R()
dic = {i: 0 for i in range(n)}
dic.update({i - 1: 1 for i in R()})
b = 0
if dic[0] == 1:
	print('1')
	exit()
for i in range(k):
	(x, y) = R()
	if b == x - 1:
		b = y - 1
	elif b == y - 1:
		b = x - 1
	if dic[b] == 1:
		(print(b + 1), exit())
print(b + 1)


(n, m, k) = map(int, input().split())
hole = set(map(int, input().split()))
fall = 0
current = 1
for i in range(k):
	if fall == 0 and current in hole:
		fall = current
	(u, v) = map(int, input().split())
	if u == current:
		current = v
	elif v == current:
		current = u
if fall != 0:
	print(fall)
else:
	print(current)


ans = -1
size = int(1000000.0 + 100)
(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
vis = [0] * size
for i in range(len(h)):
	vis[h[i]] = 1
pos = int(1)
for i in range(k):
	(x, y) = map(int, input().split())
	flag = 1
	if x == pos:
		if vis[y]:
			ans = y
			flag = 0
		else:
			pos = y
	elif y == pos:
		if vis[x]:
			ans = x
			flag = 0
		else:
			pos = x
	if flag == 0:
		break
if ans == -1:
	ans = pos
if vis[1]:
	ans = 1
print(ans)


(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
ishole = [0] * (n + 1)
for i in h:
	ishole[i] = 1
pos = 1
for i in range(k):
	(u, v) = map(int, input().split())
	if pos == u and ishole[u] == 0:
		pos = v
	elif pos == v and ishole[v] == 0:
		pos = u
	if ishole[pos] == 1:
		break
print(pos)


import sys
(n, m, k) = map(int, sys.stdin.readline().rstrip().split(' '))
holes = {}
for _ in range(1):
	for i in sys.stdin.readline().rstrip().split(' '):
		holes[i] = True
curPos = '1'
if curPos in holes:
	finalPos = '1'
else:
	finalPos = None
	moves = sys.stdin.readlines()
	for line in moves:
		(a, b) = line.rstrip().split(' ')
		if a == curPos:
			curPos = b
		elif b == curPos:
			curPos = a
		if curPos in holes:
			finalPos = curPos
			curPos = -1
			break
if finalPos:
	print(finalPos)
else:
	print(curPos)


(m, n, k) = input().split()
m = int(m)
n = int(n)
k = int(k)
location = input().split()
D = {}
bone = 1
for val in location:
	D[int(val)] = 1
flag = 0
try:
	if D[bone] == 1:
		flag = 1
except:
	pass
for i in range(k):
	(p, q) = input().split()
	p = int(p)
	q = int(q)
	if flag == 0 and (bone == p or bone == q):
		if bone == p:
			bone = q
			try:
				if D[bone] == 1:
					flag = 1
			except:
				pass
		elif bone == q:
			bone = p
			try:
				if D[bone] == 1:
					flag = 1
			except:
				pass
print(bone)


R = lambda : map(int, input().split())
(n, m, k) = R()
h = set(R())
cb = 1
for _ in range(k):
	(u, v) = R()
	if cb in h:
		break
	if u == cb:
		cb = v
	elif v == cb:
		cb = u
print(cb)


(n, m, k) = map(int, input().split())
holes = [False for i in range(1000006)]
cups = [0 for i in range(1000006)]
cups[1] = 1
holesaux = [int(i) for i in input().split()]
for i in range(m):
	holes[holesaux[i]] = True
last = 1
flag = False
for i in range(k):
	(a, b) = map(int, input().split())
	if cups[b] == 1:
		(a, b) = (b, a)
	if holes[b] == True and cups[a] == 1 and (flag == False):
		last = b
		flag = True
	elif holes[b] == False and cups[a] == 1 and (flag == False):
		(cups[a], cups[b]) = (cups[b], cups[a])
		last = b
if holes[1] == True:
	print(1)
else:
	print(last)


infos = input().split()
buracos = [False for x in range(int(infos[0]) + 1)]
for i in input().split():
	buracos[int(i)] = True
posicaoOsso = 1
for i in range(int(infos[2])):
	entrada = input()
	if not buracos[posicaoOsso]:
		entrada = [int(x) for x in entrada.split()]
		if posicaoOsso == entrada[0] or posicaoOsso == entrada[1]:
			if buracos[entrada[0]]:
				posicaoOsso = entrada[0]
			elif buracos[entrada[1]]:
				posicaoOsso = entrada[1]
			else:
				posicaoOsso = entrada[0] if posicaoOsso == entrada[1] else entrada[1]
print(posicaoOsso)


import sys

def solve():
	(n, m, k) = map(int, sys.stdin.readline().split())
	h = set((int(i) - 1 for i in sys.stdin.readline().split()))
	pos = 0
	if pos in h:
		print(pos + 1)
		return
	for i in range(k):
		(u, v) = map(int, sys.stdin.readline().split())
		(u, v) = (u - 1, v - 1)
		if u == pos:
			pos = v
		elif v == pos:
			pos = u
		else:
			continue
		if pos in h:
			print(pos + 1)
			return
	print(pos + 1)

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None
solve()


(N, M, K) = map(int, input().split())
H = set(list(map(int, input().split())))
pos = 1
if pos in H:
	print(pos)
	exit()
for k in range(K):
	(u, v) = map(int, input().split())
	if u == pos:
		pos = v
	elif v == pos:
		pos = u
	if pos in H:
		print(pos)
		exit()
print(pos)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = defaultdict(int)
(n, m, k) = M()
l = L()
for i in l:
	d[i] += 1
s = 0
key = 1
if d[1]:
	print(1)
else:
	for i in range(k):
		(a, b) = M()
		if a == key or b == key:
			if a == key:
				key = b
				if d[key]:
					print(b)
					exit()
			else:
				key = a
				if d[key]:
					print(a)
					exit()
	print(key)


(n, m, k) = map(int, input().split())
l = list(map(int, input().split()))
l2 = [0] * 1000003
for i in l:
	l2[i] = 1
if l2[1] == 1:
	print(1)
	exit()
x = 1
for i in range(k):
	(a, b) = map(int, input().split())
	if a == x:
		x = b
		if l2[x] == 1:
			print(x)
			exit()
	elif b == x:
		x = a
		if l2[x] == 1:
			print(x)
			exit()
print(x)


[n, m, k] = [int(x) for x in input().split()]
positionOfHoles = set((int(x) for x in input().split()))
u = 1
for x in range(k):
	[a, b] = [int(x) for x in input().split()]
	if u == a:
		if u in positionOfHoles:
			break
		u = b
	elif u == b:
		if u in positionOfHoles:
			break
		u = a
print(u)


def solution():
	(n, m, k) = [int(x) for x in input().split(' ')]
	h = [int(x) for x in input().split(' ')]
	holes = {}
	for i in h:
		holes[str(i)] = True
	h = []
	moves = []
	for i in range(k):
		moves.append(tuple([int(x) for x in input().split(' ')]))
	x = 1
	if '1' in holes:
		return x
	for move in moves:
		if move[0] == x:
			x = move[1]
			if str(move[1]) in holes:
				return x
			continue
		if move[1] == x:
			x = move[0]
			if str(move[0]) in holes:
				return x
	return x
print(solution())


import sys
(n, m, k) = map(int, input().split())
a = [int(i) - 1 for i in input().split()]
b = [0] * n
for i in a:
	b[i] = 1
now = 0
for i in range(k):
	if b[now]:
		print(now + 1)
		sys.exit(0)
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	if now == x:
		now = y
	elif now == y:
		now = x
print(now + 1)


(n, _, k) = map(int, input().split())
st = set(map(int, input().split()))
pos = 1
if 1 in st:
	print(1)
	exit()
for i in range(k):
	(a, b) = map(int, input().split())
	if a == pos:
		pos = b
	elif b == pos:
		pos = a
	if pos in st:
		print(pos)
		exit()
print(pos)


entrada1 = str(input())
lista = entrada1.split()
n = int(lista[0])
m = int(lista[1])
k = int(lista[2])
posini = 0
listapos = [0 for i in range(n)]
entrada2 = str(input())
lista2 = entrada2.split()
lista2 = [int(i) for i in lista2]
for a in lista2:
	if a == 1:
		print('1')
		exit(0)
	else:
		listapos[a - 1] = -1
for i in range(k):
	entrada3 = str(input())
	lista3 = entrada3.split()
	u = int(lista3[0]) - 1
	v = int(lista3[1]) - 1
	if posini == u:
		posini = v
	elif posini == v:
		posini = u
	if listapos[posini] == -1:
		print(posini + 1)
		exit(0)
print(posini + 1)


(n, m, k) = map(int, input().split())
h = {int(x) for x in input().split()}
p = 1
for t in range(k):
	(u, v) = map(int, input().split())
	if p in h:
		break
	elif p == u:
		p = v
	elif p == v:
		p = u
print(p)


(n, m, k) = [int(x) for x in input().strip().split(' ')]
holes = set([int(x) for x in input().strip().split(' ')])
bone = 1
fall = bone in holes
i = 0
while i < k and (not fall):
	(a, b) = [int(x) for x in input().strip().split(' ')]
	if a == bone:
		bone = b
	elif b == bone:
		bone = a
	fall = bone in holes
	i += 1
print(bone)


(n, m, k) = map(int, input().split())
h = set([i for i in input().split()])
ans = chk = '1'
while k:
	k = k - 1
	if ans in h:
		break
	(x, y) = map(str, input().split())
	if x == ans:
		ans = y
	elif y == ans:
		ans = x
print(ans)


(n, m, k) = list(map(int, input().split()))
hole = [False for _ in range(n)]
for h in input().split():
	hh = int(h) - 1
	hole[hh] = True
bone = 0
fallen = hole[0]
for _ in range(k):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	if not fallen:
		if bone == a:
			bone = b
		elif bone == b:
			bone = a
		fallen = hole[bone]
print(bone + 1)


(_, _, k) = map(int, input().split())
holes = set(map(int, input().split()))
pos = 1
for i in range(k):
	if pos in holes:
		break
	(x1, x2) = map(int, input().split())
	if x1 == pos:
		pos = x2
	elif x2 == pos:
		pos = x1
print(pos)


[n, m, k] = [int(i) for i in input().split()]
arr = [0 for i in range(n)]
for i in input().split():
	arr[int(i) - 1] = 1
current = int(1)
hole = False
if arr[0] == 0:
	for i in range(k):
		[a, b] = [int(p) for p in input().split()]
		if a == current or b == current:
			if a == current and (not hole):
				current = b
				if arr[b - 1] != 0:
					hole = True
			elif not hole:
				current = a
				if arr[a - 1] != 0:
					hole = True
print(current)


(n, m, k) = map(int, input().split())
holes = list(map(int, input().split()))
holes_memory = [1] * 1000006
for h in holes:
	holes_memory[h] = 0
final = 1
for i in range(k):
	temp = list(map(int, input().split()))
	if temp[0] == final or temp[1] == final:
		if holes_memory[final] == 0:
			break
		if holes_memory[temp[0]] == 0:
			final = temp[0]
			break
		elif holes_memory[temp[1]] == 0:
			final = temp[1]
			break
		if temp[1] == final:
			final = temp[0]
		else:
			final = temp[1]
print(final)


import sys

def solve():
	inp = sys.stdin.readline
	(n, _, k) = map(int, inp().split())
	st = [0] * (n + 5)
	for i in map(int, inp().split()):
		st[i] = 1
	pos = 1
	if st[1]:
		print(1)
		exit()
	for i in range(k):
		(a, b) = map(int, inp().split())
		if a == pos:
			pos = b
		elif b == pos:
			pos = a
		if st[pos]:
			print(pos)
			exit()
	print(pos)
solve()


(numberOfHoles, numberOfCups, numberOfSwaps) = [int(x) for x in input().split(' ')]
positionsOfHoles = set([int(x) for x in input().split(' ')])
positionOfBone = 1
for x in range(numberOfSwaps):
	if positionOfBone in positionsOfHoles:
		break
	(positionOne, positionTwo) = [int(x) for x in input().split(' ')]
	if positionOfBone == positionOne:
		positionOfBone = positionTwo
	elif positionOfBone == positionTwo:
		positionOfBone = positionOne
print(positionOfBone)


(n, m, k) = map(int, input().split())
l = set(map(int, input().split()))
i = 1
for _ in range(k):
	(u, v) = map(int, input().split())
	if i in l:
		break
	if i == u:
		i = v
	elif i == v:
		i = u
print(i)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
(n, m, k) = R()
h = set(L())
bone = 1
for i in range(k):
	(u, v) = R()
	if bone in h:
		print(bone)
		exit()
	if u == bone:
		bone = v
	elif v == bone:
		bone = u
print(bone)


leitura = input().split()
num_copos = int(leitura[0])
posicao = []
for i in range(num_copos):
	posicao.append(False)
num_buracos = int(leitura[1])
qtd_operacoes = int(leitura[2])
pos_osso = 1
caiu = False
buracos = input().split()
for i in buracos:
	posicao[int(i) - 1] = True
for i in range(len(buracos)):
	buracos[i] = int(buracos[i])
for i in range(qtd_operacoes):
	if posicao[pos_osso - 1]:
		caiu = True
		break
	operacao = input().split()
	if not caiu and (int(operacao[0]) == pos_osso or int(operacao[1]) == pos_osso):
		if int(operacao[1]) == pos_osso:
			pos_osso = int(operacao[0])
		else:
			pos_osso = int(operacao[1])
print(pos_osso)


(n, m, k) = list(map(int, input().split()))
d = {}
if m > 0:
	for x in map(int, input().split()):
		d[x] = True
ball = 1
for i in range(k):
	if ball in d:
		break
	(x, y) = list(map(int, input().split()))
	ball = x if ball == y else y if ball == x else ball
print(ball)


(n, m, k) = map(int, input().split())
l = list(map(int, input().split()))
l = set(l)
p = 1
q = 1
if 1 in l:
	print(1)
	q = -1
if q > 0:
	for i in range(k):
		(a, b) = map(int, input().split())
		if a == p:
			p = b
		elif b == p:
			p = a
		if p in l:
			break
	print(p)


import sys

def ints_input():
	return [int(i) for i in sys.stdin.readline().strip('\n').split(' ')]

def print_list(arr):
	sys.stdout.writelines((str(x) + ' ' for x in arr))
	sys.stdout.write('\n')

def fast_input(type=str):
	return type(sys.stdin.readline().strip('\n'))
(n, m, k) = ints_input()
holes = set(ints_input())
ans = 1
for i in range(k):
	(u, v) = ints_input()
	if ans in holes:
		print(ans)
		exit()
	if u == ans:
		ans = v
		continue
	if v == ans:
		ans = u
print(ans)


from sys import stdin
hat = stdin.readlines()
k = int(hat[0].split()[2])
holes = {int(x) for x in hat[1].split()}
pos = 1
for i in range(k):
	(a, b) = map(int, hat[i + 2].split())
	if pos in holes:
		break
	elif pos == a:
		pos = b
	elif pos == b:
		pos = a
print(pos)


from sys import stdin
(n, m, k) = (int(i) for i in stdin.readline().strip().split(' '))
h = {int(i) for i in stdin.readline().strip().split(' ')}
bone = 1
while k >= 0:
	if bone in h:
		break
	k -= 1
	line = stdin.readline().strip()
	if len(line):
		(u, v) = tuple((int(i) for i in line.split(' ')))
		if bone == u:
			bone = v
		elif bone == v:
			bone = u
print(bone)


(n, m, k) = list(map(int, input().split()))
holes = set(map(int, input().split()))
l = []
index = 1
for i in range(k):
	if index in holes:
		break
	(before, after) = list(map(int, input().split()))
	if index == before:
		index = after
	elif index == after:
		index = before
print(index)


(n, m, k) = map(int, input().split(' '))
h = set([int(x) for x in input().split(' ')])
p = 1
f = 0 if p not in h else 1
for _ in range(k):
	(a, b) = map(int, input().split(' '))
	if a == p and f == 0:
		if b in h:
			f = 1
		p = b
	elif b == p and f == 0:
		if a in h:
			f = 1
		p = a
	else:
		pass
print(p)


from bisect import bisect_left
(n, m, k) = map(int, input().split(' '))
holes = list(map(int, input().split(' ')))
curr = 1
found = False
holes = sorted(holes)
H = len(holes)

def bins(x, bot, top=None):
	top = top if top is not None else H
	pos = bisect_left(holes, x, bot, top)
	return pos != top and holes[pos] == x
if curr in holes:
	print(curr)
	found = True
else:
	for a0 in range(k):
		(u, v) = map(int, input().split(' '))
		if u == curr:
			curr = v
			if bins(curr, 0):
				print(curr)
				found = True
				break
		elif v == curr:
			curr = u
			if bins(curr, 0):
				print(curr)
				found = True
				break
if not found:
	print(curr)


(N, M, K) = map(int, input().strip().split())
holes = set((int(x) for x in input().strip().split()))
pos = 1
if pos not in holes:
	for i in range(K):
		(a, b) = map(int, input().strip().split())
		if pos == a:
			pos = b
		elif pos == b:
			pos = a
		if pos in holes:
			break
print(pos)


(n, m, k) = [int(s) for s in input().split()]
a = [0 for i in range(n + 1)]
b = [int(s) for s in input().split()]
for i in range(len(b)):
	a[b[i]] = 1
if a[1] > 0:
	print(1)
else:
	p = 1
	for i in range(k):
		b = [int(s) for s in input().split()]
		if p == b[0]:
			p = b[1]
		elif p == b[1]:
			p = b[0]
		if a[p] > 0:
			break
	print(p)


def solve():
	res = 1
	(n, m, k) = map(int, input().split())
	holes = [False] * (n + 1)
	tmp = list(map(int, input().split()))
	for i in tmp:
		holes[i] = True
	if holes[1] == True:
		return 1
	else:
		while k != 0:
			k = k - 1
			(a, b) = map(int, input().split())
			if holes[res] == True:
				continue
			if a == res:
				res = b
			elif b == res:
				res = a
	return res
print(solve())


(n, m, k) = input().split(' ')
k = int(k)
holes = {}
lista = input().split(' ')
for i in lista:
	holes[i] = 1
where = '1'
found = False
for i in range(k):
	pos = input().split(' ')
	if not found:
		if where not in holes:
			if where == pos[0]:
				where = pos[1]
			elif where == pos[1]:
				where = pos[0]
print(where)


(c, h, s) = list(map(int, input().split()))
holes = list(map(int, input().split()))
d = [0] * (c + 1)
for i in range(h):
	d[holes[i]] = 1
cup = 1
if not 1 in holes:
	for i in range(s):
		(a, b) = list(map(int, input().split()))
		if cup == a and (not d[a]):
			cup = b
		elif cup == b and (not d[b]):
			cup = a
		if d[cup]:
			break
print(cup)


from collections import deque
(n, m, k) = map(int, input().split())
holes = list(map(int, input().split()))
d = deque()
freq = [0] * (n + 1)
for i in holes:
	freq[i] += 1
if freq[1] == 1:
	print(1)
	exit(0)
pos = 1
f = deque()
for i in range(k):
	(u, v) = map(int, input().split())
	if pos == u:
		pos = v
		if freq[pos] == 1:
			f.append(pos)
	elif pos == v:
		pos = u
		if freq[pos] == 1:
			f.append(pos)
if len(f) != 0:
	print(f[0])
else:
	print(pos)


(n, m, k) = (int(v) for v in input().split())
(b, h) = (1, set())
for v in input().split():
	h.add(int(v))
for i in range(k):
	(u, v) = (int(v) for v in input().split())
	if b in h:
		break
	if u != b:
		(u, v) = (v, u)
	if u != b:
		continue
	b = v
print(b)


(n, m, k) = [int(i) for i in input().split()]
holes = [int(i) for i in input().split()]
isHole = {}
for i in range(1, n + 1):
	isHole[i] = 0
for i in holes:
	isHole[i] = 1
if isHole[1]:
	print(1)
	exit(0)
cur = 1
for i in range(0, k):
	(a, b) = [int(i) for i in input().split()]
	if a != cur and b != cur:
		continue
	else:
		cur = a + b - cur
	if isHole[cur]:
		print(cur)
		exit(0)
print(cur)


def intput():
	return [int(x) for x in input().split()]

def main():
	(N, M, K) = intput()
	buraco = set(intput())
	osso = 1
	for k in range(K):
		if osso in buraco:
			break
		else:
			(u, v) = intput()
			if u == osso:
				osso = v
			elif v == osso:
				osso = u
	print(osso)
main()


import sys
(n, m, k) = map(int, input().strip().split(' '))
holes = list(map(int, input().strip().split(' ')))
is_hole = dict()
for hole in holes:
	if hole == 1:
		print(1)
		sys.exit(0)
	is_hole[hole] = 1
bone = 1
for _ in range(k):
	(u, v) = map(int, input().strip().split(' '))
	if bone not in [u, v]:
		continue
	if v == bone:
		(u, v) = (v, u)
	bone = v
	try:
		if is_hole[v] == 1:
			break
	except KeyError:
		continue
print(bone)


def main():
	(n, m, k) = map(int, input().split())
	holes = [0] * n
	holesaux = input().split()
	for hole in holesaux:
		holes[int(hole) - 1] = True
	bone = 0
	for _ in range(int(k)):
		if holes[bone] == True:
			print(bone + 1)
			return
		(u, v) = input().split()
		u = int(u) - 1
		v = int(v) - 1
		if u == bone:
			bone = v
		elif v == bone:
			bone = u
	print(bone + 1)
main()


iters = int(input().split()[2])
holes = {int(x) for x in input().split()}
current = 1
for _ in range(iters):
	(src, dest) = (int(x) for x in input().split())
	if current in holes:
		break
	if current == src:
		current = dest
	elif current == dest:
		current = src
print(current)


def inp(n):
	if n == 1:
		return map(int, stdin.readline().split())
	elif n == 2:
		return map(float, stdin.readline().split())
	else:
		return map(str, stdin.readline().split())

def arr_inp():
	return [int(x) for x in stdin.readline().split()]

def arr_2d(n):
	return [[int(x) for x in stdin.readline().split()] for i in range(n)]
from sys import stdin
from collections import defaultdict
(n, m, k) = inp(1)
(h, swap, bone) = (arr_inp(), arr_2d(k), 1)
h = defaultdict(int, {h[i]: 1 for i in range(m)})
if h[bone]:
	exit(print(bone))
for i in swap:
	if i[0] == bone:
		bone = i[1]
	elif i[1] == bone:
		bone = i[0]
	if h[bone]:
		exit(print(bone))
print(bone)


def parse():
	numbers = list(map(int, input().split()))
	n = numbers[0]
	k = numbers[2]
	holes = [False for i in range(n)]
	for hole in list(map(int, input().split())):
		holes[hole - 1] = True
	swaps = []
	for i in range(k):
		swaps.append(list(map(int, input().split())))
	return [n, holes, swaps]

def find_bone(case):
	holes = case[1]
	swaps = case[2]
	current_bone = 1
	if holes[current_bone - 1]:
		return 1
	for swap in swaps:
		first = swap[0]
		second = swap[1]
		if current_bone == first:
			current_bone = second
		elif current_bone == second:
			current_bone = first
		if holes[current_bone - 1]:
			return current_bone
	return current_bone

def solve():
	inputs = parse()
	print(find_bone(inputs))
solve()


(n, m, k) = map(int, input().split())
l = [x for x in range(1, n + 1)]
bone = 1
holes = [0] * (n + 1)
for h in map(int, input().split()):
	holes[h] = 1
bone = 1
for i in range(k):
	(f, t) = map(int, input().split())
	if f == bone and holes[f] == 0:
		bone = t
	elif t == bone and holes[t] == 0:
		bone = f
print(bone)


(n, m, k) = map(int, input().split())
holes = {int(i): 0 for i in input().split()}
poss = [False] * (n + 1)
poss[1] = True
ans = 1
if 1 in holes:
	ans = 1
else:
	for i in range(k):
		(x, y) = map(int, input().split())
		if poss[x] and y in holes:
			ans = y
			for j in range(i + 1, k):
				input()
			break
		if poss[y] and x in holes:
			ans = x
			for j in range(i + 1, k):
				input()
			break
		if poss[y]:
			poss[y] = False
			poss[x] = True
			ans = x
		elif poss[x]:
			poss[x] = False
			poss[y] = True
			ans = y
print(ans)


import sys

def solve():
	(n, m, k) = map(int, sys.stdin.readline().split())
	h = [int(i) - 1 for i in sys.stdin.readline().split()]
	is_hole = [False] * n
	for hi in h:
		is_hole[hi] = True
	pos = 0
	if is_hole[pos]:
		print(pos + 1)
		return
	for i in range(k):
		(u, v) = map(int, sys.stdin.readline().split())
		(u, v) = (u - 1, v - 1)
		if u != pos and v != pos:
			continue
		if u != pos:
			pos = u
		elif v != pos:
			pos = v
		if is_hole[pos]:
			print(pos + 1)
			return
	print(pos + 1)

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def __starting_point():
	solve()
__starting_point()


(n, m, k) = map(int, input().split())
H = set(map(int, input().split()))
bone_pos = 1
if bone_pos not in H:
	for i in range(k):
		(u, v) = map(int, input().split())
		if bone_pos == u:
			bone_pos = v
		elif bone_pos == v:
			bone_pos = u
		if bone_pos in H:
			break
print(bone_pos)


import collections, heapq, itertools, math
groupby = itertools.groupby
rs = lambda : input()
ri = lambda : int(input())
rm = lambda : map(int, input().split())
rai = lambda : [int(x) for x in input().split()]

def solve(n, m, k, h, pos):
	holes = set(h)
	cur_pos_bone = 1
	if 1 in holes:
		return 1
	for (u, v) in pos:
		if u == cur_pos_bone:
			cur_pos_bone = v
		elif v == cur_pos_bone:
			cur_pos_bone = u
		if cur_pos_bone in holes:
			break
	return cur_pos_bone

def main():
	(n, m, k) = rm()
	h = rai()
	pos = []
	for _ in range(k):
		(a, b) = rm()
		pos.append((a, b))
	print(solve(n, m, k, h, pos))
main()


(_, _, n) = [int(x) for x in input().split(' ')]
holes = {int(x) for x in input().split(' ')}
if 1 in holes:
	print(1)
else:
	current_cup = 1
	for _ in range(n):
		(c1, c2) = [int(x) for x in input().split(' ')]
		if c1 == current_cup or c2 == current_cup:
			if c1 == current_cup:
				current_cup = c2
			else:
				current_cup = c1
			if current_cup in holes:
				break
	print(current_cup)


(n, m, k) = list(map(int, input().split()))
ip = list(map(int, input().split()))
holes = [0 for i in range(n + 1)]
for i in ip:
	holes[i] = 1
pos = 1
b = 0
if holes[1] == 1:
	b = 1
for i in range(k):
	(u, v) = list(map(int, input().split()))
	if u == pos and b == 0:
		pos = v
		if holes[v] == 1:
			b = 1
	elif v == pos and b == 0:
		pos = u
		if holes[u] == 1:
			b = 1
print(pos)


nmk = input().split()
n = int(nmk[0])
m = int(nmk[1])
k = int(nmk[2])
dic = {}
x = 1
holes = input().split()
for i in range(0, m):
	dic.setdefault(int(holes[i]), 1)
for i in range(0, k):
	if dic.get(x, 0):
		break
	uv = input().split()
	u = int(uv[0])
	v = int(uv[1])
	if dic.get(v) == 1 and x == u:
		x = v
		break
	if dic.get(u) == 1 and x == v:
		x = u
		break
	if u == x:
		x = v
		continue
	if v == x:
		x = u
print(x)


(n, m, k) = list(map(int, input().split()))
a = list(map(int, input().rstrip().split()))
a.insert(0, 0)
c = [False] * (10 ** 6 + 1)
for i in range(1, m + 1):
	c[a[i]] = True
initial = 1
ans = 1
for i in range(k):
	(f, d) = list(map(int, input().split()))
	if c[initial] == True:
		ans = initial
		break
	elif initial == f:
		initial = d
		ans = initial
	elif initial == d:
		initial = f
		ans = initial
	if c[initial] == True:
		ans = initial
		break
print(ans)


from sys import stdin

def main():
	(s, t, *l) = stdin.read().splitlines()
	(mm, x) = (set(t.split()), '1')
	while not l[-1]:
		del l[-1]
	for (u, v) in map(str.split, l):
		if x in mm:
			break
		if x == u:
			x = v
		elif x == v:
			x = u
	print(x)
main()


x = -1
boneat = 1
l = input().split()
n = int(l[0])
m = int(l[1])
k = int(l[2])
boolList = []
for i in range(n + 1):
	boolList.append(True)
l = input().split()
for i in range(m):
	boolList[int(l[i])] = False
if boolList[1] == 0:
	print(1)
	x = -5
if x != -5:
	for i in range(k):
		l = input().split()
		if int(l[0]) == boneat or int(l[1]) == boneat:
			if boolList[int(l[1])] == 0:
				x = -5
				print(l[1], end='')
				break
			elif boolList[int(l[0])] == 0:
				x = -5
				print(l[0], end='')
				break
			else:
				boneat = int(l[0]) + int(l[1]) - boneat
if x != -5:
	print(boneat, end='')


try:
	while True:
		(n, m, k) = input().split()
		holes = set(input().split())
		bone = '1'
		for i in range(int(k)):
			swap = input().split()
			if bone in holes:
				continue
			if bone == swap[0]:
				bone = swap[1]
			elif bone == swap[1]:
				bone = swap[0]
		print(int(bone), end='')
except EOFError:
	pass


(n, m, k) = map(int, input().split())
l = map(int, input().split())
used = [False] * (n + 1)
for h in l:
	used[h] = True
pos = 1
(a, b) = (-1, -1)
for i in range(k):
	(a, b) = map(int, input().split())
	if used[pos]:
		break
	elif a == pos:
		pos = b
	elif b == pos:
		pos = a
print(pos)


(n, m, k) = map(int, input().split())
h = {i: True for i in map(int, input().split())}
current = 1
in_hole = 1 in h
for i in range(k):
	if in_hole:
		break
	(u, v) = map(int, input().split())
	if u == current:
		current = v
	elif v == current:
		current = u
	if current in h:
		in_hole = True
print(current)


(n, m, k) = list(map(int, input().split()))
h = set()
tmp = list(map(int, input().split()))
for i in tmp:
	h.add(i)
p = 1
for i in range(k):
	(u, v) = map(int, input().split())
	if p in h:
		break
	elif u == p:
		p = v
	elif v == p:
		p = u
print(p)


IL = lambda : list(map(int, input().split()))
IS = lambda : input().split()
I = lambda : int(input())
S = lambda : input()
(n, m, k) = IL()
h = set(IL())
pos = 1 if 1 not in h else -1
for i in range(k):
	(u, v) = IL()
	if pos == u:
		pos = v
	elif pos == v:
		pos = u
	if pos in h:
		pos = -pos
print(abs(pos))


(n, m, k) = map(int, input().split())
l = list(map(int, input().split()))
in_or_not = [0] * (n + 1)
for i in l:
	in_or_not[i] = 1
on = 1
holes = None
for i in range(k):
	(a, b) = map(int, input().split())
	if on == a:
		if in_or_not[a] == 1:
			holes = a
			print(holes)
			exit()
		if in_or_not[b] == 1:
			holes = b
			print(holes)
			exit()
		else:
			on = b
	elif on == b:
		if in_or_not[b] == 1:
			holes = b
			print(holes)
			exit()
		if in_or_not[a] == 1:
			holes = a
			print(holes)
			exit()
		else:
			on = a
print(on)


(a, b, c) = list(map(int, input().split()))
s = set(map(int, input().split()))
ans = 1
if ans not in s:
	for i in range(0, c):
		(x, y) = list(map(int, input().split()))
		if ans == x:
			ans = y
		elif ans == y:
			ans = x
		if ans in s:
			break
print(ans)


(n, m, k) = tuple(input().split(' '))
n = int(n)
m = int(m)
k = int(k)
a = [False] * n
cur = 1
for x in input().split(' '):
	a[int(x) - 1] = True
	if x is '1':
		print(1)
		exit(0)
for x in range(k):
	b = [int(y) for y in input().split(' ')]
	if b[0] == cur:
		cur = b[1]
	elif b[1] == cur:
		cur = b[0]
	if a[cur - 1]:
		print(cur)
		exit(0)
print(cur)


def main():
	(n, m, k) = list((int(i) for i in input().split()))
	holes = list((False for i in range(n + 1)))
	a = list((int(i) for i in input().split()))
	for i in a:
		holes[i] = True
	c = 1
	for i in range(k):
		if holes[c]:
			break
		(u, v) = list((int(i) for i in input().split()))
		if u == c:
			c = v
		elif v == c:
			c = u
	print(c)
main()


R = lambda : map(int, input().split())
(n, m, k) = R()
h = [0] * (n + 1)
for x in R():
	h[x] = 1
b = 1
for _ in range(k):
	(u, v) = R()
	if b == u and (not h[u]):
		b = v
	elif b == v and (not h[v]):
		b = u
print(b)


from sys import stdin
(n, m, k) = map(int, stdin.readline().split())
holes = set(map(int, stdin.readline().split()))
moves = (map(int, stdin.readline().split()) for _ in range(k))
ball = 1
for (a, b) in moves:
	if ball in holes:
		break
	if a == ball:
		ball = b
	elif b == ball:
		ball = a
print(ball)


(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
arr = [0] * n
flag = 0
for i in h:
	arr[i - 1] = 1
bone = 0
for _ in range(k):
	(a, b) = map(int, input().split())
	if a - 1 == bone or b - 1 == bone:
		if arr[bone] == 1:
			flag = 1
			print(bone + 1)
			break
		if a - 1 == bone:
			bone = b - 1
		else:
			bone = a - 1
	else:
		continue
if flag == 0:
	print(bone + 1)


__author__ = 'artyom'

def main():
	(n, m, k) = read(3)
	c = 1
	hs = [0] * (n + 1)
	for p in read(3):
		if p == c:
			return 1
		hs[p] = 1
	for i in range(k):
		(s, d) = read(3)
		if c == s:
			c = d
		elif c == d:
			c = s
		if hs[c]:
			break
	return c

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (a[0] + 1)
p = 1
for i in range(0, a[1]):
	c[b[i]] = 1
u = 0
for i in range(0, a[2]):
	d = list(map(int, input().split()))
	if d[0] == p or d[1] == p:
		if d[0] == p:
			if c[d[0]] == 1:
				p = d[0]
				u = 1
				print(p)
				break
			else:
				p = d[1]
		elif d[1] == p:
			if c[d[1]] == 1:
				p = d[1]
				u = 1
				print(p)
				break
			else:
				p = d[0]
if u == 0:
	print(p)


(n, m, k) = map(int, input().split())
data = set(map(int, input().split()))
cur = 1
for i in range(k):
	if cur in data:
		break
	(u, v) = map(int, input().split())
	if u == cur:
		cur = v
	elif v == cur:
		cur = u
print(cur)


(n, m, k) = map(int, input().split())
hs = map(int, input().split())
s_set = set(hs)
fallen = 1 in s_set
curr_pos = 1
for i in range(k):
	(u, v) = map(int, input().split())
	if fallen:
		continue
	if u == curr_pos:
		curr_pos = v
	elif v == curr_pos:
		curr_pos = u
	if curr_pos in s_set:
		fallen = True
print(curr_pos)


(n, m, k) = list(map(int, input().split()))
h = list(map(int, input().split()))
used = [0] * int(10000000.0)
for x in h:
	used[x] = 1
t = 1
for i in range(k):
	(u, v) = list(map(int, input().split()))
	if used[t]:
		print(t)
		exit(0)
	elif u == t:
		if used[v] == 1:
			print(v)
			exit(0)
		t = v
	elif v == t:
		if used[u] == 1:
			print(u)
			exit(0)
		t = u
print(t)


(n, m, k) = map(int, input().split())
l = set(map(int, input().split()))
v = 1
if v in l:
	print(1)
	exit()
for i in range(k):
	(a, b) = map(int, input().split())
	if a == v:
		v = b
	elif b == v:
		v = a
	if v in l:
		print(v)
		exit()
print(v)


import sys

def main():
	(n, m, k) = map(int, input().split())
	hole = [0 for i in range(0, n + 1)]
	l = list(map(int, input().split()))
	for x in l:
		hole[x] = 1
	ans = 1
	for i in range(k):
		if hole[ans]:
			break
		(a, b) = map(int, input().split())
		if ans != a and ans != b:
			continue
		elif ans == a:
			ans = b
		else:
			ans = a
	print(str(ans))
main()


(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
h = set(h)
now = 1
if 1 in h:
	print(1)
	exit(0)
for _ in range(k):
	(u, v) = map(int, input().split())
	if u == now:
		now = v
	elif v == now:
		now = u
	if now in h:
		print(now)
		exit(0)
print(now)


(n, m, k) = map(int, input().split())
h = set(map(int, input().split()))
bone = 1
for _ in range(k):
	(a, b) = map(int, input().split())
	if bone in h:
		break
	if a == bone:
		bone = b
	elif b == bone:
		bone = a
print(bone)


from sys import stdin
import re

def main():
	l = list(map(int, filter(None, re.split('\\W', stdin.read()))))
	(n, m, k) = l[:3]
	mm = [False] * (n + 1)
	for x in l[3:3 + m]:
		mm[x] = True
	x = 1
	for (u, v) in zip(l[3 + m::2], l[4 + m::2]):
		if mm[x]:
			break
		if x == u:
			x = v
		elif x == v:
			x = u
	print(x)
main()


(n, m, k) = map(int, input().split())
holes = {int(i) for i in input().split()}
ball = 1
for el in range(k):
	(u, v) = (int(i) for i in input().split())
	if ball in holes:
		continue
	if u == ball:
		ball = v
	elif v == ball:
		ball = u
print(ball)


(n, m, k) = map(int, input().split())
h = [0] * (n + 1)
for i in map(int, input().split()):
	h[i] = 1
pos = 1
import sys
if h[1]:
	print(1)
	sys.exit()
for _ in range(k):
	(a, b) = map(int, input().split())
	if pos == a:
		pos = b
		if h[b]:
			print(b)
			sys.exit()
	elif pos == b:
		pos = a
		if h[a]:
			print(a)
			sys.exit()
print(pos)


temp = input()
temp2 = []
temp2 = temp.split()
n = int(temp2[0])
m = int(temp2[1])
k = int(temp2[2])
temp = input()
holes = temp.split()
flag = 0
primeiro = 0
esta = 1
hole = [0] * n
for z in holes:
	hole[int(z) - 1] = int(1)
for o in range(0, k):
	temp = input()
	temp2 = []
	temp2 = temp.split()
	f = int(temp2[0])
	s = int(temp2[1])
	if flag == 0 and primeiro == 0 and (hole[0] == 1):
		flag = 1
	elif flag == 0:
		if esta == f:
			if hole[s - 1] == 1:
				esta = s
				flag = 1
			else:
				esta = s
		elif esta == s:
			if hole[f - 1] == 1:
				esta = f
				flag = 1
			else:
				esta = f
	primeiro = 1
print(esta)


(n, m, k) = map(int, input().split())
h = set(map(int, input().split()))
i = 1
for _ in range(k):
	(u, v) = map(int, input().split())
	if i in h:
		print(i)
		exit()
	if i == u:
		i = v
	elif i == v:
		i = u
print(i)


user = input().split(' ')
n = int(user[0])
m = int(user[1])
k = int(user[2])
holes = map(int, input().split(' '))
isHole = [0] * (n + 1)
for h in holes:
	isHole[h] = 1

def result():
	bone = 1
	for x in range(0, k):
		line = input()
		if isHole[bone]:
			return bone
		data = line.split(' ')
		u = int(data[0])
		v = int(data[1])
		if bone == v or bone == u:
			bone = v + u - bone
	return bone
print(result())


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, m, k) = get_ints()
	arr = get_list()
	arr = set(arr)
	hole = False
	bone = 1
	if 1 in arr:
		hole = True
	for i in range(k):
		(x, y) = get_ints()
		if x == bone and hole == False:
			bone = y
			if y in arr:
				hole = True
		elif y == bone and hole == False:
			bone = x
			if x in arr:
				hole = True
	print(bone)


from sys import stdin, stdout, exit
import math
from fractions import gcd
from bisect import bisect

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])

def issorted(li):
	n = len(li)
	for i in range(n - 1):
		if li[i] > li[i + 1]:
			return False
	return True
(n, m, k) = listInput()
holes = listInput()
table = [0] * (n + 1)
table[1] = 1
hole_tables = [0] * (n + 1)
for i in holes:
	hole_tables[i] = 1
for _ in range(k):
	(a, b) = listInput()
	if table[a] == 1:
		if hole_tables[a] == 0:
			table[b] = 1
			table[a] = 0
	elif table[b] == 1:
		if hole_tables[b] == 0:
			table[a] = 1
			table[b] = 0
print(table.index(1))


def main():
	(n, m, k) = map(int, input().split())
	h = set((int(c) for c in input().split()))
	if 1 in h:
		print(1)
		return
	cups = list(range(n + 1))
	for _ in range(k):
		(u, v) = map(int, input().split())
		(cups[u], cups[v]) = (cups[v], cups[u])
		if u in h and cups[v] == 1:
			print(u)
			return
		elif v in h and cups[u] == 1:
			print(v)
			return
	print(cups.index(1))
main()


def solve():
	(n, hi, s) = map(int, input().split())
	h = set(list(map(int, input().split())))
	pre = 1
	for i in range(s):
		(x1, x2) = map(int, input().split())
		if pre in h:
			return print(pre)
		if x1 == pre:
			pre = x2
		elif x2 == pre:
			pre = x1
	return print(pre)
solve()


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
vis = [0] * (n + 1)
for i in a:
	vis[i] = 1
pos = 1
if vis[pos] == 1:
	print(1)
	exit(0)
for i in range(k):
	(u, v) = map(int, input().split())
	if pos == u:
		pos = v
	elif pos == v:
		pos = u
	if vis[pos] == 1:
		break
print(pos)


def main():
	(n, m, k) = map(int, input().split())
	mm = [False] * (n + 1)
	for x in map(int, input().split()):
		mm[x] = True
	x = 1
	for _ in range(k):
		if mm[x]:
			break
		(u, v) = map(int, input().split())
		if x == u:
			x = v
		elif x == v:
			x = u
	print(x)
main()


(n, m, k) = map(int, input().split())
holes = set((int(hole) for hole in input().split()))
x = 1
for i in range(k):
	if x in holes:
		break
	(u, v) = map(int, input().split())
	if u == x:
		x = v
	elif v == x:
		x = u
print(x)


def main():
	(n, m, k) = map(int, input().split())
	hole = [0 for i in range(n + 1)]
	H = list(map(int, input().split()))
	box = [0 for i in range(n + 1)]
	box[1] = 1
	ans = 0
	for x in H:
		hole[x] = 1
	if hole[1]:
		ans = 1
	for i in range(k):
		(x, y) = map(int, input().split())
		if ans:
			continue
		(box[x], box[y]) = (box[y], box[x])
		if box[x] and hole[x]:
			ans = x
		if box[y] and hole[y]:
			ans = y
	if ans:
		print(ans)
	else:
		for i in range(len(box)):
			if box[i]:
				print(i)
				break
	return 0
main()


def bone():
	(n, m, k) = map(int, input().split())
	holes = set(map(int, input().split()))
	prev = 1
	for _ in range(k):
		(ini, end) = map(int, input().split())
		if prev == ini or prev == end:
			if prev in holes:
				print(prev)
				return
			prev = prev ^ ini ^ end
			if prev in holes:
				print(prev)
				return
	print(prev)
bone()


(n, m, k) = [int(x) for x in input().split()]
holes = set([int(x) for x in input().split()])
now = 1
if now in holes:
	print(1)
	exit(0)
for t in range(k):
	(i, j) = [int(x) for x in input().split()]
	if i == now:
		now = j
	elif j == now:
		now = i
	if now in holes:
		print(now)
		exit(0)
print(now)


(n, m, k) = map(int, input().split())
h = set(list(map(int, input().split())))

def solve():
	currentpos = 1
	for i in range(k):
		if currentpos in h:
			return currentpos
		(a, b) = map(int, input().split())
		if a == currentpos:
			currentpos = b
		elif b == currentpos:
			currentpos = a
	return currentpos
print(solve())


(n, m, k) = list(map(int, input().split()))
holes = list(map(int, input().split()))
is_hole = [False for i in range(n)]
for i in holes:
	is_hole[i - 1] = True
bone = 0
if is_hole[0]:
	print(1)
else:
	was = False
	for i in range(k):
		(a, b) = list(map(int, input().split()))
		a -= 1
		b -= 1
		if a == bone:
			bone = b
		elif b == bone:
			bone = a
		if is_hole[bone]:
			was = True
			print(bone + 1)
			break
	if not was:
		print(bone + 1)


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def main():
	(n, m, k) = invr()
	h = [0] * (n + 1)
	temp = inlist()
	for i in temp:
		h[i] = 1
	x = 1
	res = 0
	for _ in range(k):
		(u, v) = invr()
		if h[x] == 1:
			res = x
			continue
		if x == u:
			x = v
		elif x == v:
			x = u
	print(res if res > 0 else x)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


(n, m, k) = map(int, input().split())
s = set((int(x) for x in input().split()))
bone = 1
for i in range(k):
	if bone in s:
		print(bone)
		exit(0)
	(a, b) = map(int, input().split())
	if a == bone or b == bone:
		if b == bone:
			bone = a
		else:
			bone = b
print(bone)


def mi():
	return map(int, input().split())
(n, m, k) = mi()
h = list(mi())
hole = [0] * (n + 1)
for i in h:
	hole[i] = 1
(u, v) = (0, 0)
cur = 1
for i in range(k):
	(u, v) = mi()
	if u == cur and hole[u] == 0:
		cur = v
	elif v == cur and hole[v] == 0:
		cur = u
print(cur)


I = lambda : map(int, input().split())
(n, m, k) = I()
hole = [0] * 10 ** 6
for i in I():
	hole[i - 1] = 1
position = 1
for i in range(k):
	(x1, x2) = I()
	if hole[position - 1] != 0:
		break
	if position == x1 or position == x2:
		position = x1 + x2 - position
print(position)


(n, m, k) = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] * (n + 1)
for x in a:
	b[x] = 1
end = False
now = 1
while k:
	if b[now]:
		end = True
	(x, y) = map(int, input().split())
	if (now == x or now == y) and (not end):
		now = x + y - now
	k -= 1
print(now)


s = list(map(int, input().split()))
cups = s[0]
swapping = s[2]
l = []
for i in range(cups):
	l.append(False)
holes = list(map(int, input().split()))
p = True
for i in holes:
	if i == 1:
		p = False
		break
	l[i - 1] = True
aux = 1
for i in range(swapping):
	if p:
		swapp = list(map(int, input().split()))
		if swapp[0] == aux:
			if l[swapp[1] - 1]:
				p = False
			aux = swapp[1]
		elif swapp[1] == aux:
			if l[swapp[0] - 1]:
				p = False
			aux = swapp[0]
	else:
		input()
print(aux)


(n, m, k) = map(int, input().split())
M = list(map(int, input().split()))
H = [False] * (n + 1)
for i in M:
	H[i] = True
Bone = 1
T = True
for i in range(k):
	if H[Bone]:
		print(Bone)
		T = False
		break
	(p, s) = map(int, input().split())
	if p == Bone:
		Bone = s
		if H[s]:
			print(s)
			T = False
			break
	elif s == Bone:
		Bone = p
		if H[p]:
			print(p)
			T = False
			break
if T:
	print(Bone)


(n, m, k) = input().split()
n = int(n)
m = int(m)
k = int(k)
a = [False] * (n + 1)
for i in list(map(int, input().split())):
	a[i] = True
curr = 1
if a[curr]:
	print(curr)
	exit()
for i in range(int(k)):
	(u, v) = list(map(int, input().split()))
	if curr == u:
		curr = v
	elif curr == v:
		curr = u
	if a[curr]:
		print(curr)
		exit()
print(curr)


(n, m, k) = map(int, input().split())
h = input().split()
a = ['.'] * n
for i in h:
	a[int(i) - 1] = '*'
if a[0] != '*':
	a[0] = '^'
else:
	a[0] = '$'
for i in range(k):
	(x, y) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	if a[x] == '^':
		if a[y] == '*':
			(a[x], a[y]) = ('.', '$')
		else:
			(a[x], a[y]) = (a[y], a[x])
	elif a[y] == '^':
		if a[x] == '*':
			(a[y], a[x]) = ('.', '$')
		else:
			(a[y], a[x]) = (a[x], a[y])
for i in range(n):
	if a[i] == '^' or a[i] == '$':
		print(i + 1)


posicoes = [int(x) for x in input().split()]
buracos = [int(x) for x in input().split()]
BuracosPosicoes = [0] * posicoes[0]
for i in range(len(buracos)):
	BuracosPosicoes[buracos[i] - 1] = 1
if 1 in buracos:
	print('1')
	quit()
currentPosition = 1
for i in range(posicoes[2]):
	posicaoAtual = [int(x) for x in input().split()]
	if posicaoAtual[0] == currentPosition:
		currentPosition = posicaoAtual[1]
	elif posicaoAtual[1] == currentPosition:
		currentPosition = posicaoAtual[0]
	if BuracosPosicoes[currentPosition - 1] == 1:
		break
print(currentPosition)


import sys
inp = sys.stdin.read()
inp = inp.split('\n')
iters = int(inp[0].split()[2])
holes = {int(x) for x in inp[1].split()}
current = 1
for i in range(iters):
	(src, dest) = (int(x) for x in inp[i + 2].split())
	if current in holes:
		break
	if current == src:
		current = dest
	elif current == dest:
		current = src
print(current)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, input().split()))

def ei():
	return map(int, input().split())

def ip():
	return int(stdin.readline())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, m, k) = ei()
holes = set(ai())
initial = 1
for i in range(k):
	(a, b) = ei()
	if initial in holes:
		break
	if initial == a:
		initial = b
	elif initial == b:
		initial = a
print(initial)


(n, m, k) = map(int, input().split())
l = set(map(int, input().split()))
x = 1
for _ in range(k):
	(a, b) = map(int, input().split())
	if x in l:
		break
	if a == x:
		x = b
	elif b == x:
		x = a
print(x)


(n, m, k) = input().split()
n = int(n)
k = int(k)
buraco = input().split()
l_buraco = [False for x in range(n + 1)]
for i in buraco:
	l_buraco[int(i)] = True
bone = '1'
for i in range(k):
	(a, b) = input().split()
	if not l_buraco[int(bone)]:
		if a == bone:
			bone = b
		elif b == bone:
			bone = a
print(bone)


(n, m, k) = map(int, input().split())
set_holes = set(input().split())
prev_pos = '1'
checker = 0
lst_poses = ['1']
for i in range(k):
	(f1, f2) = input().split()
	if f1 == lst_poses[-1]:
		lst_poses.append(f2)
	elif f2 == lst_poses[-1]:
		lst_poses.append(f1)
prev_pos = lst_poses[-1]
for j in lst_poses:
	if j in set_holes:
		prev_pos = j
		break
print(prev_pos)


(n, m, k) = map(int, input().split())
h = [int(i) for i in input().split()]
bone_at = 1
hole = 0
from collections import Counter
c = Counter(h)
if c[1]:
	print(1)
	exit()
for i in range(k):
	(u, v) = map(int, input().split())
	if hole:
		continue
	elif bone_at == u and c[v]:
		hole = 1
		hole_ans = v
	elif bone_at == u:
		bone_at = v
	elif bone_at == v and c[u]:
		hole = 1
		hole_ans = u
	elif bone_at == v:
		bone_at = u
if hole:
	print(hole_ans)
else:
	print(bone_at)


from collections import defaultdict
(n, m, k) = map(int, input().split())
h = list(map(int, input().split()))
swaps = []
for _ in range(k):
	(u, v) = map(int, input().split())
	swaps.append((u, v))
d = defaultdict(bool)
for hole in h:
	d[hole] = True
current_bone_position = 1
for move in swaps:
	if d[current_bone_position]:
		print(current_bone_position)
		exit()
	if current_bone_position in move:
		(u, v) = move
		current_bone_position = v if current_bone_position == u else u
print(current_bone_position)


(n, m, k) = map(int, input().split())
holes = set(map(lambda x: int(x) - 1, input().split()))
bone = 0
done = 0 in holes
for i in range(k):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	if done:
		continue
	if bone in [a, b]:
		bone = a if bone == b else b
	if bone in holes:
		done = True
print(bone + 1)


(x, y, z) = map(int, input().split())
t = set(input().split())
kam_poz = 1
for i in range(z):
	(l, k) = map(int, input().split())
	if str(kam_poz) in t:
		break
	if kam_poz == l:
		kam_poz = k
	elif kam_poz == k:
		kam_poz = l
print(kam_poz)


from sys import stdin
(n, m, k) = [int(x) for x in stdin.readline().rstrip().split()]
h = [False] * n
u = []
v = []
res = 0
for x in stdin.readline().rstrip().split():
	h[int(x) - 1] = 1
for i in range(k):
	temp = [int(x) for x in stdin.readline().rstrip().split()]
	u.append(temp[0] - 1)
	v.append(temp[1] - 1)
for i in range(k):
	if h[res]:
		break
	if u[i] == res:
		res = v[i]
	elif v[i] == res:
		res = u[i]
print(res + 1)


from sys import stdin, stdout
(n, m, k) = map(int, stdin.readline().split())
position = set(list(map(int, stdin.readline().split())))
start = 1
for i in range(k):
	if start in position:
		break
	else:
		(a, b) = map(int, stdin.readline().split())
		if a == start:
			start = b
		elif b == start:
			start = a
stdout.write(str(start))


(n, m, k) = map(int, input().split())
holes = set(map(int, input().split()))
pos = 1
for i in range(k):
	if pos in holes:
		break
	(inicio, fim) = map(int, input().split())
	if inicio == pos:
		pos = fim
	elif fim == pos:
		pos = inicio
print(pos)


(n, m, k) = [int(s) for s in input().split(' ')]
hole_locations = [int(s) for s in input().split(' ')]
hole_array = [0] * n
for hole in hole_locations:
	hole_array[hole - 1] += 1
bone = 1
if hole_array[0] == 1:
	print(bone)
else:
	for i in range(1, k + 1):
		(u, v) = [int(s) for s in input().split(' ')]
		if u == bone:
			bone = v
			if hole_array[v - 1] == 1:
				break
		elif v == bone:
			bone = u
			if hole_array[u - 1] == 1:
				break
	print(bone)


def main():
	(n, m, k) = map(int, input().split())
	hs = list(map(lambda x: int(x) - 1, input().split()))
	holes = [False] * n
	for h in hs:
		holes[h] = True
	pos = 0
	for swap in range(k):
		if holes[pos]:
			break
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		if u == pos:
			pos = v
		elif v == pos:
			pos = u
	print(pos + 1)
main()


(n, m, k) = map(int, input().split())
holes = set(map(int, input().split()))
p = 1
f = True
for _ in range(k):
	(u, v) = map(int, input().split())
	if not f:
		continue
	elif p in holes:
		f = False
		break
	elif u == p:
		p = v
	elif v == p:
		p = u
print(p)


[cups, holes, moves] = list(map(int, input().split(' ')))
cupsPositions = [('', 0)] * cups
holesPositions = list(map(int, input().split(' ')))
for i in holesPositions:
	cupsPositions[i - 1] = ('', 1)
bonePosition = 0
finalPosition = None
cupsPositions[0] = ('B', cupsPositions[0][1])
if cupsPositions[0][1] == 1:
	bonePosition = 0
	finalPosition = 0
for m in range(0, moves):
	[toCup, fromCup] = list(map(int, input().split(' ')))
	if finalPosition != None:
		continue
	if cupsPositions[toCup - 1][0] == 'B' and cupsPositions[fromCup - 1][1] == 1:
		bonePosition = fromCup - 1
		cupsPositions[fromCup - 1] = ('B', cupsPositions[fromCup - 1][1])
		cupsPositions[toCup - 1] = ('', cupsPositions[toCup - 1][1])
		finalPosition = bonePosition
	elif cupsPositions[toCup - 1][0] == 'B':
		bonePosition = fromCup - 1
		cupsPositions[fromCup - 1] = ('B', cupsPositions[fromCup - 1][1])
		cupsPositions[toCup - 1] = ('', cupsPositions[toCup - 1][1])
	elif cupsPositions[fromCup - 1][0] == 'B' and cupsPositions[toCup - 1][1] == 1:
		bonePosition = toCup - 1
		cupsPositions[toCup - 1] = ('B', cupsPositions[toCup - 1][1])
		cupsPositions[fromCup - 1] = ('', cupsPositions[fromCup - 1][1])
		finalPosition = bonePosition
	elif cupsPositions[fromCup - 1][0] == 'B':
		bonePosition = toCup - 1
		cupsPositions[toCup - 1] = ('B', cupsPositions[toCup - 1][1])
		cupsPositions[fromCup - 1] = ('', cupsPositions[fromCup - 1][1])
if finalPosition != None:
	print(finalPosition + 1)
else:
	print(bonePosition + 1)


import sys
a = list(map(int, input().split()))
(n, m, k) = (a[0], a[1], a[2])
h = list(map(int, input().split()))
h2 = [0] * (n + 1)
for item in h:
	h2[item] = 1
(store, getone) = (1, 0)
for i in range(k):
	(l, r) = map(int, input().split())
	if l == 1 or r == 1:
		getone = 1
	if getone == 1 and (l == store or r == store):
		if h2[store] == 1:
			break
		elif l == store:
			store = r
		elif r == store:
			store = l
print(store)


import math
import random

def main(n, arr, holes):
	if 1 in holes:
		return 1
	bone_pos = 1
	for i in range(len(arr)):
		(j, k) = arr[i]
		if j == bone_pos:
			if k in holes:
				return k
			else:
				bone_pos = k
		elif k == bone_pos:
			if j in holes:
				return j
			else:
				bone_pos = j
	return bone_pos
(n, m, k) = list(map(int, input().split()))
holes = set(map(int, input().split()))
arr = []
for i in range(k):
	arr.append(list(map(int, input().split())))
print(main(n, arr, holes))


(n, m, k) = map(int, input().split())
M = set(map(int, input().split()))
b = 1
for x in range(k):
	(u, v) = map(int, input().split())
	if b in M:
		break
	if b == u:
		b = v
	elif b == v:
		b = u
print(b)


(n, m, k) = map(int, input().split())
holes = [0] * (n + 1)
for h in map(int, input().split()):
	holes[h] = 1
cur = 1
for i in range(k):
	(f, t) = map(int, input().split())
	if f == cur and holes[f] == 0:
		cur = t
	elif t == cur and holes[t] == 0:
		cur = f
print(cur)