1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
n, m, s = map(int, input().split())

seg = [tuple(map(int, input().split())) for _ in range(m)]
occupied = lambda z: any(map(lambda t: t[0] <= z and z <= t[1], seg))

point = [z for (l, r) in seg for z in (l - 1, r + 1) if 1 <= z and z <= n]

print(
    min(
        filter(lambda z: not occupied(z), point),
        key=lambda z: (abs(z - s), z),
    )
)