Buggy python submission (verdict: Runtime Error):
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N, M = map(int, input().split())
s, c = [0 for _ in range(M)], [0 for _ in range(M)]
for i in range(M):
    s[i], c[i] = map(int, input().split())
if max(s) > N:
    print(-1)
    sys.exit()
ans = ["0" for _ in range(N)]
for i in range(len(s) - 1):
    for l in range(i + 1, len(s)):
        if s[i] == s[l] and c[i] != c[l]:
            print(-1)
            sys.exit()
for i in range(M):
    ans[s[i] - 1] = str(c[i])
if ans == ["0"]:
    print(0)
    sys.exit()
if ans[0] == "0":
    print(-1)
    sys.exit()
for i in ans:
    if len(i) > 1 or int(i) < 0:
        print(-1)
        sys.exit()
print(int("".join(ans)))


Fixed submission:
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = []
if N == 1:
    for i in range(0, 10 ** N):
        ii = str(i)
        p = 0
        for l in sc:
            if int(ii[l[0] - 1]) != l[1]:
                p = 1
        if p == 0:
            ans.append(i)
    if len(ans) == 0:
        print(-1)
        sys.exit()
    print(min(ans))

else:
    for i in range(10 ** (N - 1), 10 ** N):
        ii = str(i)
        p = 0
        for l in sc:
            if int(ii[l[0] - 1]) != l[1]:
                p = 1
        if p == 0:
            ans.append(i)
    if len(ans) == 0:
        print(-1)
        sys.exit()
    print(min(ans))

Buggy python submission (verdict: Runtime Error):
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N, M = map(int, input().split())
s, c = [0 for _ in range(M)], [0 for _ in range(M)]
for i in range(M):
    s[i], c[i] = map(int, input().split())
if max(s) > N:
    print(-1)
    sys.exit()
ans = ["0" for _ in range(N)]
for i in range(len(s)-1):
    for l in range(i+1, len(s)):
        if s[i] == s[l] and c[i] != c[l]:
            print(-1)
            sys.exit()
for i in range(M):
    ans[s[i]-1] = str(c[i])
if ans[0] == "0":
    print(-1)
    sys.exit()
for i in ans:
    if len(i) > 1:
        print(-1)
        sys.exit()
print(int("".join(ans)))

Fixed submission:
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = []
if N == 1:
    for i in range(0, 10 ** N):
        ii = str(i)
        p = 0
        for l in sc:
            if int(ii[l[0] - 1]) != l[1]:
                p = 1
        if p == 0:
            ans.append(i)
    if len(ans) == 0:
        print(-1)
        sys.exit()
    print(min(ans))

else:
    for i in range(10 ** (N - 1), 10 ** N):
        ii = str(i)
        p = 0
        for l in sc:
            if int(ii[l[0] - 1]) != l[1]:
                p = 1
        if p == 0:
            ans.append(i)
    if len(ans) == 0:
        print(-1)
        sys.exit()
    print(min(ans))