n, m, s = map(int, input().split()) vecs = [] for _ in range(m): start, end = map(int, input().split()) vecs.append((start, end)) def find_empty(x, y): global vecs, s, n if x <= 0 or x > n or x == s : x = -1 if y <= 0 or y > n or y == s: y = -1 for start, end in vecs: if x >= start and x <= end: x = -1 if y >= start and y <= end: y = -1 return x if x > 0 else y for i in range(1, n+1): left = s - i right = s + i x = find_empty(left, right) if x > 0: print(x) break
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 | n, m, s = map(int, input().split()) vecs = [] for _ in range(m): start, end = map(int, input().split()) vecs.append((start, end)) def find_empty(x, y): global vecs, s, n if x <= 0 or x > n or x == s : x = -1 if y <= 0 or y > n or y == s: y = -1 for start, end in vecs: if x >= start and x <= end: x = -1 if y >= start and y <= end: y = -1 return x if x > 0 else y for i in range(1, n+1): left = s - i right = s + i x = find_empty(left, right) if x > 0: print(x) break |