Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H,W,N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([W+1,1])

# test
if xylist[0][0] == 1:
    xylist = xylist[1:]
if len(xylist) == W:
# and sum([ y for x,y in xylist]) == 2*W -1:
    1/0

# test
ans = 0

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

# test
#if Ybound <= 1:
#    1/0

print(ans)

Fixed submission:
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H, W, N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([H+1,1])

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H,W,N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([W+1,1])

# test
ans = 0

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

# test
if Ybound <= 1:
    1/0

print(ans)

Fixed submission:
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H, W, N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([H+1,1])

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H,W,N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([W+1,1])
#if xylist[0][0] == 1:
#    xylist = xylist[1:]

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Fixed submission:
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H, W, N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([H+1,1])

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []
Nxy = 0

H,W,N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < Nxy:
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])
        Nxy += 1

xylist.sort(key=lambda x: x[0])
xylist.append([W+1,1])
# Nxy += 1
if xylist[0][0] == 1:
    xylist = xylist[1:]
    # Nxy -= 1

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X -1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Fixed submission:
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H, W, N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([H+1,1])

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class increment:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(increment())
xylist = []
Nxy = 0

H,W,N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < Nxy:
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])
        Nxy += 1

xylist.sort(key=lambda x: x[0])
xylist.append([W+1,1])
Nxy+=1
if xylist[0][0] == 1:
    xylist = xylist[1:]

Xprev = Yprev = 1
for i in range(Nxy):
    X, Y = xylist[i]
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X -1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)

Fixed submission:
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class Counter:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(Counter())
xylist = []

H, W, N = inpl()
for i in range(N):
    X, Y = inpl()
    n = ui[X]
    if n < len(xylist):
        xylist[n][1] = min(xylist[n][1],Y)
    else:
        xylist.append([X,Y])

xylist.sort(key=lambda x: x[0])
xylist.append([H+1,1])

Xprev = Yprev = 1
for X, Y in xylist:
    Ybound = Yprev + X - Xprev 
    if Y < Ybound:
        ans = X - 1
        break
    elif Y == Ybound:
        Xprev, Yprev = X, Ybound - 1
    else:
        Xprev, Yprev = X, Ybound

print(ans)