ranges = []
for line in open('input.txt', 'r'):
    ranges.append(tuple(map(int, line.split('-'))))
ranges.sort()

lowest = 0
for l, r in ranges:
    if l <= lowest <= r:
        lowest = r + 1

print(lowest)
input()

ranges = []
for line in open('input.txt', 'r'):
    ranges.append(tuple(map(int, line.split('-'))))
ranges.sort()

lowest = 0
for l, r in ranges:
    if l > lowest:
        break
    if lowest <= r:
        lowest = r + 1

print(lowest)
input()

Break the loop at the first gap
Break the loop at the first gap

  ranges = []
  for line in open('input.txt', 'r'):
      ranges.append(tuple(map(int, line.split('-'))))
  ranges.sort()
  
  lowest = 0
  for l, r in ranges:
+     if l > lowest:
+         break
-     if l <= lowest <= r:
+     if lowest <= r:
          lowest = r + 1
  
  print(lowest)
  input()
  
Break the loop at the first gap
## Code Before:
ranges = []
for line in open('input.txt', 'r'):
    ranges.append(tuple(map(int, line.split('-'))))
ranges.sort()

lowest = 0
for l, r in ranges:
    if l <= lowest <= r:
        lowest = r + 1

print(lowest)
input()

## Instruction:
Break the loop at the first gap
## Code After:
ranges = []
for line in open('input.txt', 'r'):
    ranges.append(tuple(map(int, line.split('-'))))
ranges.sort()

lowest = 0
for l, r in ranges:
    if l > lowest:
        break
    if lowest <= r:
        lowest = r + 1

print(lowest)
input()
