Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A_list = []
dic_A = {}
flag = True
for i in range(M):
    A = list(map(int, input().split()))
    if A[0] in dic_A:
        if dic_A[A[0]]!=A[1]:
            flag = False
    else:
        dic_A[A[0]] = A[1]
    A_list.append(A)
for i in range(M):
    if A_list[i][0]==1 and A_list[i][1]==0:
        flag = False
if flag == False:
    print(-1)
else:
    ans = ["0" for i in range(3)]
    for i, v in sorted(dic_A.items()):
        v = str(v)
        ans[i-1] = v
    if "".join(ans)[0] != "0":
        N, M = map(int, input().split())
A_list = []
dic_A = {}
flag = True
for i in range(M):
    A = list(map(int, input().split()))
    if A[0] in dic_A:
        if dic_A[A[0]]!=A[1]:
            flag = False
    else:
        dic_A[A[0]] = A[1]
    A_list.append(A)
for i in range(M):
    if A_list[i][0]==1 and A_list[i][1]==0:
        flag = False
if flag == False:
    print(-1)
else:
    ans = ["0" for i in range(3)]
    for i, v in sorted(dic_A.items()):
        v = str(v)
        ans[i-1] = v
    if "".join(ans)[0] != "0":
        print(int("".join(ans)))
    else:
        print(-1)

Fixed submission:
N, M = map(int, input().split())
sc_list = []
for i in range(M):
    sc = list(map(int, input().split()))
    sc_list.append(sc)
ans = -1
for i in range(10**N):
    tmp = str(i)
    if len(tmp)==N:
        flag = True
        for j in sc_list:
            if int(tmp[j[0]-1])!=j[1]:
                flag = False
        if flag:
            ans = int(tmp)
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A_list = []
dic_A = {}
flag = True
for i in range(M):
    A = list(map(int, input().split()))
    if A[0] in dic_A:
        if dic_A[A[0]]!=A[1]:
            flag = False
    else:
        dic_A[A[0]] = A[1]
    A_list.append(A)
for i in range(M):
    if A_list[i][0]==1 and A_list[i][1]==0:
        flag = False
if flag == False:
    print(-1)
else:
    ans = []
    cnt = 1
    for i, v in sorted(dic_A.items()):
        if cnt==N+1:
            break
        if cnt!=i:
            while(cnt!=i):
                ans.append(str(0))
                cnt+=1
        v = str(v)
        ans.append(v)
        cnt+=1
    if "".join(ans)[0] != "0":
        print(int("".join(ans)))
    else:
        print(-1)

Fixed submission:
N, M = map(int, input().split())
sc_list = []
for i in range(M):
    sc = list(map(int, input().split()))
    sc_list.append(sc)
ans = -1
for i in range(10**N):
    tmp = str(i)
    if len(tmp)==N:
        flag = True
        for j in sc_list:
            if int(tmp[j[0]-1])!=j[1]:
                flag = False
        if flag:
            ans = int(tmp)
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A_list = []
dic_A = {}
flag = True
for i in range(M):
    A = list(map(int, input().split()))
    if A[0] in dic_A:
        if dic_A[A[0]]!=A[1]:
            flag = False
    else:
        dic_A[A[0]] = A[1]
    A_list.append(A)
for i in range(M):
    if A_list[i][0]==1 and A_list[i][1]==0:
        flag = False
if flag == False:
    print(-1)
else:
    ans = []
    cnt = 1
    for i, v in sorted(dic_A.items()):
        if cnt==N+1:
            break
        if cnt!=i:
            while(cnt!=i):
                ans.append(str(0))
                cnt+=1
        v = str(v)
        ans.append(v)
        cnt+=1
    print(int("".join(ans)))

Fixed submission:
N, M = map(int, input().split())
sc_list = []
for i in range(M):
    sc = list(map(int, input().split()))
    sc_list.append(sc)
ans = -1
for i in range(10**N):
    tmp = str(i)
    if len(tmp)==N:
        flag = True
        for j in sc_list:
            if int(tmp[j[0]-1])!=j[1]:
                flag = False
        if flag:
            ans = int(tmp)
            break
print(ans)