Buggy python submission (verdict: Runtime Error):
a = input().split(" ")
N = int(a[0])
M = int(a[1])
ans1 = 10
ans2 = 10
ans3 = 10
x = 0
for i in range(M):
    b = input().split(" ")
    c = int(b[0])
    d = int(b[1])
    if c == 1:
        if d == 0:
            if N == 1:
                ans1 = 0
            else:
                x = 1
        elif ans1 == 10:
            ans1 = d
        elif ans1 != d:
            x = 1
    elif c == 2:
        if ans2 == 10:
            ans2 = d
        elif ans2 != d:
            x = 1
    else:
        if ans3 == 10:
            ans3 = d
        elif ans3 != d:
            x = 1
if ans1 == 10:
    ans1 = 0
if ans2 == 10:
    ans2 = 0
if ans3 == 10:
    ans3 = 0

if x = 1:
    print(-1)
else:
    if N == 1:
        print(ans1)
    elif N == 2:
        if ans1 == 0:
            print(-1)
        else:
            print(str(ans1) + str(ans2))
    else:
        if ans1 == 0:
            print(-1)
        else:
            print(str(ans1) + str(ans2) + str(ans3))

Fixed submission:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
ans1 = 10
ans2 = 10
ans3 = 10
x = 0
for i in range(M):
    b = input().split(" ")
    c = int(b[0])
    d = int(b[1])
    if c == 1:
        if ans1 == 10:
            if d == 0:
                if N == 1:
                    ans1 = 0
                else:
                    x = 1
            else:
                ans1 = d
        elif ans1 != d:
            x = 1
    elif c == 2:
        if ans2 == 10:
            ans2 = d
        elif ans2 != d:
            x = 1
    else:
        if ans3 == 10:
            ans3 = d
        elif ans3 != d:
            x = 1
if ans1 == 10:
    if N == 1:
        ans1 = 0
    else:
        ans1 = 1
if ans2 == 10:
    ans2 = 0
if ans3 == 10:
    ans3 = 0

if x == 1:
    print(-1)
else:
    if N == 1:
        print(ans1)
    elif N == 2:
        if ans1 == 0:
            print(-1)
        else:
            print(str(ans1) + str(ans2))
    else:
        if ans1 == 0:
            print(-1)
        else:
            print(str(ans1) + str(ans2) + str(ans3))

Buggy python submission (verdict: Runtime Error):
a = input().split(" ")
N = int(a[0])
M = int(a[1])
ans1 = 10
ans2 = 10
ans3 = 10
for i in range(M):
    b = input().split(" ")
    c = int(b[0])
    d = int(b[1])
    if c == 1:
        if d == 0:
            if N == 1:
                ans1 = d:
        elif d < ans1:
            ans1 = d
    elif c == 2:
        if d < ans2:
            ans2 = d
    else:
        if d < ans3:
            ans3 = d
if ans1 == 10:
    ans1 = 0
if ans2 == 10:
    ans2 = 0
if ans3 == 10:
    ans3 = 0
if N == 1:
    print(ans1)
elif N == 2:
    if ans1 == 0:
        print(-1)
    else:
        print(str(ans1) + str(ans2))
else:
    if ans1 == 0:
        print(-1)
    else:
        print(str(ans1) + str(ans2) + str(ans3))

Fixed submission:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
ans1 = 10
ans2 = 10
ans3 = 10
x = 0
for i in range(M):
    b = input().split(" ")
    c = int(b[0])
    d = int(b[1])
    if c == 1:
        if ans1 == 10:
            if d == 0:
                if N == 1:
                    ans1 = 0
                else:
                    x = 1
            else:
                ans1 = d
        elif ans1 != d:
            x = 1
    elif c == 2:
        if ans2 == 10:
            ans2 = d
        elif ans2 != d:
            x = 1
    else:
        if ans3 == 10:
            ans3 = d
        elif ans3 != d:
            x = 1
if ans1 == 10:
    if N == 1:
        ans1 = 0
    else:
        ans1 = 1
if ans2 == 10:
    ans2 = 0
if ans3 == 10:
    ans3 = 0

if x == 1:
    print(-1)
else:
    if N == 1:
        print(ans1)
    elif N == 2:
        if ans1 == 0:
            print(-1)
        else:
            print(str(ans1) + str(ans2))
    else:
        if ans1 == 0:
            print(-1)
        else:
            print(str(ans1) + str(ans2) + str(ans3))