1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
in1 = input().split()
n = int(in1[0])
m = int(in1[1])
s = int(in1[2])

res = 0
rc = 0
se = []

for x in range(m):
    inp = input().split()
    se.append(int(inp[0]))
    se.append(int(inp[1]))

se.sort()

ne = 1

for x in range(0, m):
    l = se[2*x]
    r = se[2*x + 1]
    if ne < l:
        check = abs(s - ne)
        if res == 0 or check < rc:
            res = ne
            rc = check
        check = abs(s - l + 1)
        if check < rc:
            res = l - 1
            rc = check
    ne = r + 1

check = abs(s - ne)
if res == 0 or (ne <= n and check < rc):
    res = ne

print(res)