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
def main():
    n,m,s=list(map(int,input().split()))
    p=[]
    for i in range(m):
        p.append(list(map(int,input().split())))
    p.sort()
    z=10**18
    x=0
    t=1
    h=0
    for a,b in p:
        if t!=a:
            if abs(t-s)<z:
                z=abs(t-s)
                h=t
            if abs(a-1-s)<z:
                z=abs(a-1-s)
                h=a-1
        t=b+1
    if t<=n and abs(t-s)<z:
        h=t
    print(h)
main()