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
import sys

command = input().split(" ")

n = int(command[0])
m = int(command[1])
s = int(command[2]) - 1

map_arr = [0] * n

for x in range(0, m):
    interval = input().split(" ")
    l = int(interval[0]) - 1
    r = int(interval[1]) - 1

    for y in range(l, r+1):
        map_arr[y] = 1

not_found = True
idx = 1

while not_found:

    if s - idx >= 0:
         if map_arr[s - idx] == 0:
            print (str((s - idx)+1))
            sys.exit(0)

    if s + idx < n:
        if map_arr[s + idx] == 0:
            print(str((s + idx)+1))
            sys.exit(0)

    idx+=1


print(map_arr)