qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,M = map(int,input().split())
S = [list(map(int,input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
check = [0 for _ in range(N)]
for i in range(M):
    s = S[i][0]
    c = S[i][1]
    if check[s-1] == 0:
        check[s-1] = 1
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            e = 1
            break
if e == 1:
    print(-1)
elif e != 1:
    if ans[0] == 0:
        if N == 1:
            print(0)
        else:
            print(-1)
    else:
        d = 0
        for i in range(N):
            d += ans[i] * (10 ** (N-1-i))
            print(d)

Fixed code:
N,M = map(int,input().split())
S = [list(map(int,input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
check = [0 for _ in range(N)]
e = 0
for i in range(M):
    s = S[i][0]
    c = S[i][1]
    if check[s-1] == 0:
        check[s-1] = 1
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            e = 1
            break
if e == 1:
    print(-1)
else:
    if ans[0] == 0:
        if N == 1:
            print(0)
        else:
            if check[0] == 0:
                ans[0] = 1
                d = 0
                for i in range(N):
                    d += ans[i] * (10 ** (N-1-i))
                print(d)
            else:
                print(-1)

    else:
        d = 0
        for i in range(N):
            d += ans[i] * (10 ** (N-1-i))
        print(d)
Buggy code:
def solution():
    n, m = map(int, input().split())
    cs = [list(map(int, input().split())) for i in range(m)]
    if m == 0:
        if n > 1:
            print("-1")
        else:
            print("0")
        return
    ans = [-1 for i in range(n)]
    for w in cs:
        s = w[0]
        c = w[0]
        if (s == 1) and (c == 0) and (n > 1):
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ans = [str(i) if i != -1 else str(0) for i in ans]
    anss = ''
    for s in ans:
        anss = anss + s
    print(int(anss))

solution()


Fixed code:
def solution():
    n, m = map(int, input().split())
    cs = [list(map(int, input().split())) for i in range(m)]
    if m == 0:
        if n > 1:
            print(10**(n-1))
        else:
            print("0")
        return
    ans = [-1 for i in range(n)]
    for w in cs:
        s, c = w[0], w[1]
        if (s == 1) and (c == 0) and (n > 1):
            print('-1')
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != c:
            print('-1')
            return
    ansb = [str(i) if i != -1 else str(0) for i in ans]
    if (ansb[0] == '0') and (len(ansb) > 1):
        ansb[0] = '1'
    anss = ''
    for s in ansb:
        anss = anss + s
    print(anss)

solution()
Buggy code:
import itertools

N, M = map(int, input().split())
a = [[0] * 10] * N

for i in range(N):
  if i == 0:
    a[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  else:
    a[i] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

flag = 1

for i in range(M):
  s, c = map(int, input().split())
  if N > 1 and s == 1 and c == 0 or a[s-1] != [c]:
    flag = 0
  a[s-1] = [c]

if flag == 0:
  print(-1)
elif N == 1 and M == 0:
  print(0)
else:
  list_a = list(itertools.product(*a))
  ans = ""
  for i in range(N):
    ans += str(list_a[0][i])
  print(int(ans))

Fixed code:
import itertools
 
N, M = map(int, input().split())
a = [[0] * 10] * N
 
for i in range(N):
  if i == 0:
    a[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  else:
    a[i] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
flag = 1
 
for i in range(M):
  s, c = map(int, input().split())
  if (N > 1 and s == 1 and c == 0) or (len(a[s-1]) == 1 and a[s-1] != [c]):
    flag = 0
  a[s-1] = [c]
 
if N == 1 and M == 0:
  print(0)
elif flag == 0:
  print(-1)
else:
  list_a = list(itertools.product(*a))
  ans = ""
  for i in range(N):
    ans += str(list_a[0][i])
  print(int(ans))
Buggy code:
def main():
  N, M = map(int,input().split())
  sc = list(list(input().split()) for _ in range(M))

  li = [""] * N

  for i in range(M):
    j = li[int(sc[i][0]) - 1]
    if j == "": li[int(sc[i][0]) - 1] = sc[i][1]
    elif j != sc[i][1]: return -1

  for i in range(N):
    if i == 0:
      if li[0] == "0" and N != 1: return -1
      if li[0] == "":
        if N == 1: li[0] = "0"
        elif: li[0] = "1"
    elif li[i] == "": li[i] = "0"

  return "".join(li)

print(main())

Fixed code:
def main():
  N, M = map(int,input().split())
  sc = list(list(input().split()) for _ in range(M))

  li = [""] * N

  for i in range(M):
    j = li[int(sc[i][0]) - 1]
    if j == "": li[int(sc[i][0]) - 1] = sc[i][1]
    elif j != sc[i][1]: return -1

  for i in range(N):
    if i == 0:
      if li[0] == "0" and N != 1: return -1
      if li[0] == "":
        if N == 1: li[0] = "0"
        else: li[0] = "1"
    elif li[i] == "": li[i] = "0"

  return "".join(li)

print(main())
Buggy code:
N,M = map(int,input().split())

X = [0] * N
R = [0] *  N

ans = True
for i in range(M):
    s,c = map(int,input().split())
    
        
    if R[s-1] == 0:
        X[s-1] = c
        R[s-1] = "T"
        
    elif R[s-1] == "T" and X[s-1] != c or (s == 1 and c == 0):
        ans = False
        break
        
if ans:
    if X[0] == 0:
            cnt = 1
    else:
        cnt = X[0]
    for i in range(1,N):
        cnt = cnt * 10 + X[i]
        
    print(cnt)

else:
    print(-1)

Fixed code:
N,M = map(int,input().split())

X = [0] * N
R = [0] *  N

ans = True
for i in range(M):
    s,c = map(int,input().split())
    
        
    if R[s-1] == 0:
        X[s-1] = c
        R[s-1] = "T"
        
    elif R[s-1] == "T" and X[s-1] != c :
        ans = False
        break
        
if ans:
    if X[0] == 0 and R[0] == 0 and N != 1:
        cnt = "1"
    else:
        cnt = str(X[0])
    for i in range(1,N):
        cnt = cnt + str(X[i])
    
    if len(cnt) == len(str(int(cnt))):
        
        print(cnt)
    else:
        print(-1)
else:
    print(-1)
Buggy code:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
result = [-1] * N

if M == 0:


for i in range(1, M + 1):
    s, c = map(int, input().split())
    if result[s - 1] == -1:
        result[s - 1] = c
    elif result[s - 1] == c:
        continue
    else:
        print(-1)
        exit(0)

if N != 1 and result[0] == 0:
    print(-1)
    exit(0)

if N == 1 and result[0] == -1:
    print(0)
    exit(0)

if N != 1 and result[0] == -1:
    result[0] = 1

for i in range(len(result)):
    if result[i] == -1:
        print(0, end="")
    else:
        print(result[i], end="")
print()


Fixed code:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
result = [-1] * N

for i in range(1, M + 1):
    s, c = map(int, input().split())
    if result[s - 1] == -1:
        result[s - 1] = c
    elif result[s - 1] == c:
        continue
    else:
        print(-1)
        exit(0)

if N != 1 and result[0] == 0:
    print(-1)
    exit(0)

if N == 1 and result[0] == -1:
    print(0)
    exit(0)

if N != 1 and result[0] == -1:
    result[0] = 1

for i in range(len(result)):
    if result[i] == -1:
        print(0, end="")
    else:
        print(result[i], end="")
print()
Buggy code:
N, M = map(int, input().split())
exists = True
digits = [-1]*N
for i in range(M):
    s, c = map(int, input().split())
    if N > 1 and s == 1 and c == 0:
        exists = False
        break
    elif digits[s-1] == -1 or digits[s-1] == c:
        digits[s-1] = c
    else:
        exists = False
        break
if exists:
    ans = 0
    digits = list(reversed(digits))
    for i in range(N):
        if digits[i] == -1:
            digits[i] = 0
        ans += (10 ** i)*digits[i]
    print(digits)
    print(ans)
else:
    print(-1)


Fixed code:
N, M = map(int, input().split())
exists = True
digits = [-1]*N
for i in range(M):
    s, c = map(int, input().split())
    if N > 1 and s == 1 and c == 0:
        exists = False
        break
    elif digits[s-1] == -1 or digits[s-1] == c:
        digits[s-1] = c
    else:
        exists = False
        break
if exists:
    ans = 0
    digits = list(reversed(digits))
    for i in range(N):
        if digits[i] == -1:
            if i == N - 1 and N > 1:
                digits[i] = 1
            else:
                digits[i] = 0
        ans += (10 ** i)*digits[i]
    print(ans)
else:
    print(-1)
Buggy code:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
start=10**(n-1)
end=10**n
if n == 1:
    start = 0
for i in range(start,end):
    i=str(i)
    for s,c in sc:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        break
print(-1)

Fixed code:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
start=10**(n-1)
end=10**n
if n == 1:
    start = 0
for i in range(start,end):
    i=str(i)
    for s,c in sc:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print(-1)
Buggy code:
N, M = map(int, input().split())

guess = []
for _ in range(M):
  s, c = map(int, input().split())
  guess.append([s, c])

for n in range(pow(10, N)):
  if (len(str(n)) != N):
    continue
  
  valid = True
  for s_c in guess:
    keta = s_c[0]
    index = keta - 1
    if (str(n)[index] != str(s_c[1])):
      valid = False
      break
  
  if (valid == False):
    continue
  else:
    print(n)
    return

print(-1)

Fixed code:
N, M = map(int, input().split())

guess = []
for _ in range(M):
  s, c = map(int, input().split())
  guess.append([s, c])

result = -1
for n in range(pow(10, N)):
  if (len(str(n)) != N):
    continue
  
  valid = True
  for s_c in guess:
    keta = s_c[0]
    index = keta - 1
    if (str(n)[index] != str(s_c[1])):
      valid = False
      break
  
  if (valid == False):
    continue
  else:
    result = n
    break

print(result)
Buggy code:
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
for i in range(1000):
    s = str(i)
    flag = True
    for j,k in li:
        if j > len(s):
            flag = False
            break
        if s[j-1] != str(k):
            flag = False
    if flag:
        print(s)
        exit()
print(-1)

Fixed code:
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
for i in range(1000):
    s = str(i)
    if len(s) != n:
        continue
    flag = True
    for j,k in li:
        if s[j-1] != str(k):
            flag = False
    if flag:
        print(s)
        exit()
print(-1)
Buggy code:
n,m = map(int,input().split())
c = [[] for _ in range(n)]
for i in range(m):
    s,x = map(int,input().split())
    c[s-1].append(x)

r = 0
d = [-1 for _ in range(n)]

for i in range(n):
    if len(set(c[i])) > 1:
        r = -1
        break
    elif len(c[i]) == 0:
        continue
    else:
        d[i] = c[i][0]

if r == -1:
    print(r)
else:
    if n == 3:
        if d[0] == -1:
            d[0] = 1
        if d[1] == -1:
            d[1] = 0
        if d[2] == -1:
            d[2] = 0
    elif n == 2:
        if d[0] == -1:
            d[0] = 1
        if d[1] == -1:
            d[1] = 0
    else:
        if d[0] == -1:
            d[0] = 0
    print(''.join(map(str,d)))

Fixed code:
n,m = map(int,input().split())
c = [[] for _ in range(n)]
for i in range(m):
    s,x = map(int,input().split())
    c[s-1].append(x)

r = 0
d = [-1 for _ in range(n)]

for i in range(n):
    if len(set(c[i])) > 1:
        r = -1
        break
    elif len(c[i]) == 0:
        continue
    else:
        if i == 0 and n > 1 and c[i][0] == 0:
            r = -1
            break
        d[i] = c[i][0]

if r == -1:
    print(r)
else:
    if n == 3:
        if d[0] == -1:
            d[0] = 1
        if d[1] == -1:
            d[1] = 0
        if d[2] == -1:
            d[2] = 0
    elif n == 2:
        if d[0] == -1:
            d[0] = 1
        if d[1] == -1:
            d[1] = 0
    else:
        if d[0] == -1:
            d[0] = 0
    print(''.join(map(str,d)))
Buggy code:
N,M = [int(i) for i in input().split()]
S = []
C = []

for i in range(M):
   s,c = [int(i) for i in input().split()]
   S.append(s)
   C.append(c)

ans = [0] * N
for i in range(M):
    if ans[S[i] - 1] != 0:
        print(-1)
        exit()
    ans[S[i]-1] = C[i]


if ans[0] == 0:
    print(-1)
else:
    print(''.join(map(str,ans)))

Fixed code:
N,M = [int(i) for i in input().split()]
S = []
C = []

for i in range(M):
   s,c = [int(i) for i in input().split()]
   S.append(s)
   C.append(c)

ans = [-1] * N
for i in range(M):
    if ans[S[i] - 1] != -1 and ans[S[i] - 1] != C[i]:
        print(-1)
        exit()
    elif S[i] - 1 == 0 and C[i] == 0 and N != 1:
        print(-1)
        exit()
    ans[S[i]-1] = C[i]

for i in range(1,N):
    if ans[i] == -1:
        ans[i] = 0

if ans[0] == -1 and N != 1:
    ans[0] = 1
elif N == 1 and ans[0] == -1:
    ans[0] = 0

print(''.join(map(str,ans)))
Buggy code:
import sys
N,M = map(int,input().split())
cc = [list(map(int, input().split())) for i in range(M)]
if [0,1] in cc:
  if N!= 1:
    print(-1)
    sys.exit()
a,b = [0]*N,['v']*N
for [i,j] in cc:
  a[i-1] = j
  if b[i-1] != 'v' or b[i-1] != j:
    print(-1)
    sys.exit
  b[i-1] = j
if a[0] = 0:
  a[0] = 1
c = ''
for i in a:
  c = c + str(i)
print(c)
  
  
    

Fixed code:
import sys
N,M = map(int,input().split())
cc = [list(map(int, input().split())) for i in range(M)]
if [1,0] in cc:
  if N!= 1:
    print(-1)
    sys.exit()
a,b = [0]*N,['v']*N
for [i,j] in cc:
  a[i-1] = j
  if b[i-1] != 'v' and b[i-1] != j:
    print(-1)
    sys.exit()
  b[i-1] = j
if a[0] == 0:
  if N != 1:
    a[0] = 1
c = ''
for i in a:
  c = c + str(i)
print(c)
Buggy code:
n, m = map(int, input().split())
tmp = [10]*n

for _ in range(m):
    s,c = map(int, input().split())
    tmp[s-1] = min(tmp[s-1],c)
for i in range(n):
    if tmp[i] == 10:
        if i == 0 and n != 1:
            tmp[i] = 1
        else:
            tmp[i] = 0

ans = ''.join(map(str,tmp))

if n != 1 and ans[0] == 0:
    print('-1')
else:
    print(ans)

Fixed code:
n, m = map(int, input().split())
tmp = [10]*n

for _ in range(m):
    s,c = map(int, input().split())
    if tmp[s-1] == 10 or tmp[s-1]==c:
        tmp[s-1] = c
    else:
        print('-1')
        exit()

for i in range(n):
    if tmp[i] == 10:
        if i == 0 and n != 1:
            tmp[i] = 1
        else:
            tmp[i] = 0

ans = ''.join(map(str,tmp))

if n != 1 and ans[0] == '0':
    print('-1')
else:
    print(ans)
Buggy code:
n,m = map(int,input().split())
 
c = []
for i in range(m):
    c.append(list(map(int,input().split())))
 

ans = -1
if m == 0:
    ans = pow(10,n-1)
elif n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = i
else:            
 for i in range(pow(10,n-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i
print(ans)   

Fixed code:
n,m = map(int,input().split())
 
c = []
for i in range(m):
    c.append(list(map(int,input().split())))
 

ans = -1
if n == 1 and m == 0:
    ans = 0
elif m == 0 and n != 1:
    ans = pow(10,n-1)
elif n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = c[0][1]
            break
else:            
 for i in range(pow(10,n-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i
         break
print(ans)
Buggy code:
N,M=map(int,input().split())
Sc=[list(map(int,input().split())) for _ in range(M)]

D=['-1']*N

for sc in Sc:
    s,c=sc[0],sc[1]
    if s==1 and c==0 and N==0:
        print(-1)
        exit()
    if D[s-1]!='-1' and D[s-1]!=str(c):
        print(-1)
        exit()
    D[s-1]=str(c)
if D[0]=='-1':
    D[0]='1'
for i in range(1,N):
    if D[i]=='-1':
        D[i]='0'
 
print(''.join(D))

Fixed code:
N,M=map(int,input().split())
Sc=[list(map(int,input().split())) for _ in range(M)]

D=['-1']*N

for sc in Sc:
    s,c=sc[0],sc[1]
    if s==1 and c==0 and N>1:
        print(-1)
        exit()
    if D[s-1]!='-1' and D[s-1]!=str(c):
        print(-1)
        exit()
    D[s-1]=str(c)
if D[0]=='-1' and N==1:
    D[0]='0'
elif D[0]=='-1' and N>1:
    D[0]='1'
for i in range(1,N):
    if D[i]=='-1':
        D[i]='0'
 
print(''.join(D))
Buggy code:
nm=input("").split(" ")
n=int(nm[0])
m=int(nm[1])
lists=[-1]*n
ss=0
for i in range(m):
    sc=input("").split(" ")
    s=int(sc[0])
    c=int(sc[1])
    if(s==1 and c==0):
        ss=1
    elif(lists[s-1]==-1):
        lists[s-1]=c
    elif(lists[s-1]==c):
        None
    else:
        ss=1
if(ss==1):
    print(-1)
else:

    pp=""
    for i in range(n):
        if(lists[i]==-1):
            pp+="1"
        else:
            pp+=str(lists[i])
    print(int(pp))
        


Fixed code:
nm=input("").split(" ")
n=int(nm[0])
m=int(nm[1])
lists=[-1]*n
ss=0
if(n==1):
    tt=-1
    for i in range(m):
        sc=input("").split(" ")
        s=int(sc[0])
        c=int(sc[1])
        if(tt==-1):
            tt=c
        elif(tt==c):
            None
        else:
            ss=1
    if(ss==1):
        print(-1)
    elif(m==0):
        print(0)
    else:
        print(tt)
        

else:
    for i in range(m):
        sc=input("").split(" ")
        s=int(sc[0])
        c=int(sc[1])
        if(s==1 and c==0):
            ss=1
        elif(lists[s-1]==-1):
            lists[s-1]=c
        elif(lists[s-1]==c):
            None
        else:
            ss=1
    if(ss==1):
        
            
        print(-1)
        
    else:

        pp=""
        for i in range(n):
            if(lists[i]==-1 and i!=0):
                pp+="0"
            elif(lists[i]==-1):
                pp+="1"
            else:
                pp+=str(lists[i])
        print(int(pp))
Buggy code:
n, m = map(int, input().split())
x = [0] * m
y = [0] * m
r = [0] * n
t = [0] * n
for i in range(m):
    x[i], y[i] = map(int, input().split())
    if t[x[i] - 1] == 0 and r[x[i] - 1] == y[i]:
        r[x[i] - 1] = y[i]
        t[x[i] - 1] = 1
    else:
        print(-1)
        exit()
if n > 1 and r[0] == 0:
    print(-1)
else:
    print(*r, sep='')


Fixed code:
n, m = map(int, input().split())
x = [0] * m
y = [0] * m
r = [0] * n
t = [0] * n
for i in range(m):
    x[i], y[i] = map(int, input().split())
    if t[x[i] - 1] == 0:
        r[x[i] - 1] = y[i]
        t[x[i] - 1] = 1
    else:
        if r[x[i] - 1] != y[i]:
            print(-1)
            exit()
if n>1 and r[0] == 0 and t[0] == 0:
    r[0] = 1
elif n > 1 and r[0] == 0 and t[0] != 0:
    print(-1)
    exit()
print(*r, sep='')
Buggy code:
import sys
input = sys.stdin.readline

def main():

    N, M = map(int, input().split())
    Set = []
    for i in range(M):
        Set.append(list(map(int, input().split())))

    for i in range(10**N):
        num = str(i)
        if len(i) == N and all(num[s-1]==str(c) for s,c in Set):
            print(i)
            break
    else:
        print(-1)


if __name__ == '__main__':
    main()

Fixed code:
import sys
input = sys.stdin.readline

def main():

    N, M = map(int, input().split())
    Set = []
    for i in range(M):
        Set.append(list(map(int, input().split())))

    for i in range(10**N):
        num = str(i)
        if len(num) == N and all(num[s-1]==str(c) for s,c in Set):
            print(i)
            break
    else:
        print(-1)


if __name__ == '__main__':
    main()
Buggy code:
N,M=map(int,input().split())
d=[-1 for _ in range(N)]
for m in range(M):
  s,c=map(int,input().split())
  if d[s-1]==-1:
    d[s-1]=c
  elif d[s-1]!=c:
    print(-1)
    exit()

if N>1:
	if d[0]==0:
    print(-1)
    exit()
  elif d[0]==-1:
  	d[0]=1

A=0
for i in range(N):
  A=A*10+(d[i] if d[i]!=-1 else 0)

print(A)


Fixed code:
N,M=map(int,input().split())
d=[-1 for _ in range(N)]
for m in range(M):
  s,c=map(int,input().split())
  if d[s-1]==-1:
    d[s-1]=c
  elif d[s-1]!=c:
    print(-1)
    exit()

if N>1:
  if d[0]==0:
    print(-1)
    exit()
  elif d[0]==-1:
  	d[0]=1

A=0
for i in range(N):
  A=A*10+(d[i] if d[i]!=-1 else 0)

print(A)
Buggy code:
N, M = map(int, input().split())
SC = set(tuple(map(int, input().split())) for _ in range(M))

for i in range(10**N):
    num = str(i)
    if len(num) != N:
        continue
    chk = True
    for s, c in SC:
        print(s, c, num)
        if num[s-1] != str(c):
            chk = False
    if chk == True:
        print(num)
        exit()
print(-1)

Fixed code:
N, M = map(int, input().split())
SC = set(tuple(map(int, input().split())) for _ in range(M))

for i in range(10**N):
    num = str(i)
    if len(num) != N:
        continue
    chk = []
    for s, c in SC:
        if num[s-1] == str(c):
            chk.append(True)
        else:
            chk.append(False)
    if all(chk):
        print(num)
        exit()
print(-1)
Buggy code:
N,M = map(int,input().split())
sc = list([list(map(int,input().split())) for _ in range(M)])


for i in range(10**(N-1)-1,10**N):
    count = 0
    str_i = str(i)
    for j in range(M):
        if str_i[sc[j][0]-1] == str(sc[j][1]):
            count += 1
    if count == M:
        print(i)
        exit()
print(-1)


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

if N == 1:
    a = 0
elif N != 1:
    a = 10 **(N-1)

for i in range(a,10**N):
    count = 0
    str_i = str(i)
    for j in range(M):
        if str_i[sc[j][0]-1] == str(sc[j][1]):
            count += 1
    if count == M:
        print(i)
        exit()
print(-1)
Buggy code:
in1 = input('')
n = int(in1.split(' ')[0])
m = int(in1.split(' ')[1])
l = []
for i in range(0,n):
  l.append(0)

hasError = False
for i in range(0,m):
  in2 = input('')
  idx = int(in2.split(' ')[0])
  li = int(in2.split(' ')[1])
  if l[idx-1] != li:
    hasError = True
  else:
    l[idx-1] = li

result = 0
for i in range(0,n):
  ix = 1
  for j in range(0,(n-i-1)):
    ix*=10
  result += int(l[i])*ix

if result < 0:
  result = -1
if n == 1 and result == 0:
  result = 0
elif len(str(result)) != n:
  result = -1
if hasError = True:
  result = -1
print(result)



Fixed code:
in1 = input('')
n = int(in1.split(' ')[0])
m = int(in1.split(' ')[1])
l = []
for i in range(0,n):
  l.append(-1)

hasError = False
for i in range(0,m):
  in2 = input('')
  idx = int(in2.split(' ')[0])-1
  li = int(in2.split(' ')[1])
  if l[idx] != -1 and l[idx] != li:
    hasError = True
  else:
    l[idx] = li

for i in range(0,n):
  if l[i] == -1:
    if i == 0 and n > 1:
      l[i] = 1
    else:
      l[i] = 0

result = 0
for i in range(0,n):
  ix = 1
  for j in range(0,(n-i-1)):
    ix*=10
  result += int(l[i])*ix

if result < 0:
  result = -1
if n == 1 and result == 0:
  result = 0
elif len(str(result)) != n:
  result = -1
if hasError == True:
  result = -1
print(result)
Buggy code:
N, M = map(int, input().split())
a = [[] for _ in range(N)]
for i in range(M):
  s, c = map(int, input().split())
  a[s-1].append(c)
flag = 0
ans = [0]*N
for i in range(len(a)):
  if len(set(a[i]))>1:
    flag = 1
    break
  elif a[i]:
    ans[i] = a[i][0]
if a[0][0] == 0:
  flag = 1
ans = ''.join((str(n) for n in ans))
if flag == 0:
  if a[0] == 0:
    a[0] = 1
  ans = ''.join((str(n) for n in ans))
  print(int(ans))
else:
  print(-1)

Fixed code:
N, M = map(int, input().split())
a = [[] for _ in range(N)]
flag = 0
for i in range(M):
  s, c = map(int, input().split())
  a[s-1].append(c)
ans = [0]*N
 
for i in range(len(a)): 
  if i == 0 and a[i]:
    if len(a) == 1:
      pass
    elif len(set(a[i]))> 1 or 0 in a[i]:
      flag = 1
      break
    else:
      ans[i] = a[i][0] 
  if len(set(a[i]))>1:
    flag = 1
    break
  elif a[i]:
    ans[i] = a[i][0]
if flag == 0:
  if ans[0] == 0:
    if len(a) == 1:
      ans[0] = 0
    else:
      ans[0] = 1
  ans = ''.join((str(n) for n in ans))
  print(int(ans))
else:
  print(-1)