qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, m = map(int, input().split())
ans = [-1] * n
exist = True
for i in range(m):
    s, c = map(int, input().split())
    if (n != 1 and (s, c) == (1, 0)) or (ans[s - 1] != -1 and ans[s - 1] != c):
        exist = False
        break
    else:
        ans[s - 1] = c

if exist:
    for i in range(n):
    if n != 1 and i == 0:
        if ans[i] == -1:
            ans[i] = 1
    else:
        if ans[i] == -1:
            ans[i] = 0

    print(*ans, sep='')
else:
    print(-1)

Fixed code:
n, m = map(int, input().split())
ans = [-1] * n
exist = True
for i in range(m):
    s, c = map(int, input().split())
    if (n != 1 and (s, c) == (1, 0)) or (ans[s - 1] != -1 and ans[s - 1] != c):
        exist = False
        break
    else:
        ans[s - 1] = c

for i in range(n):
    if n != 1 and i == 0:
        if ans[i] == -1:
            ans[i] = 1
    else:
        if ans[i] == -1:
            ans[i] = 0
if exist:
    print(*ans, sep='')
else:
    print(-1)
Buggy code:
#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)
for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i in range(dig, dig*10):
    flag = False
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()

Fixed code:
#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)

for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i in range(0, dig*10):
    flag = False
    if len(str(i)) < n:
        continue
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()

print("-1")
Buggy code:
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  flags_assigned = [0]*N
  for _ in range(M):
    new_s = int(s.pop())
    new_c = int(c.pop())
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return -1
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return -1
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]

print(assign_digits(ans))
  


Fixed code:
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return [str(-1)]
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return [str(-1)]
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int("".join(assign_digits(ans))))
Buggy code:
N,M= map(int,input().split())
s=[]
c=[]
ans=-1
for i in range(M):
    s_i,c_i=input().split()
    s.append(int(s_i))
    c.append(c_i)
for i in range(int("1"+"0"*(N-1)),int("9"*N)+1):
    ans_bool=True
    for j in range(M):
        ans_bool=ans_bool and str(i)[s[j]-1]==str(c[j])
    if ans_bool:
        ans=i
        
print(ans)


Fixed code:
N,M= map(int,input().split())
s=[]
c=[]
ans=-1
for i in range(M):
    s_i,c_i=input().split()
    s.append(int(s_i))
    c.append(c_i)
if N==1:
    for i in range(10):
        ans_bool=True
        for j in range(M):
            ans_bool=ans_bool and str(i)[s[j]-1]==str(c[j])
        if ans_bool:
            ans=i
            break
else:
    for i in range(int("1"+"0"*(N-1)),int("9"*N)+1):
        ans_bool=True
        for j in range(M):
            ans_bool=ans_bool and str(i)[s[j]-1]==str(c[j])
        if ans_bool:
            ans=i
            break
        
print(ans)
Buggy code:
# input
N, M = map(int, input().split())

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

if (1, 0) in c:
    print(-1)
else:
    ans = -1

    # check
    for i in range(1000):
        str_i = str(i)

        if N < len(str_i):
            break

        if False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
            ans = i
            break

    print(ans)

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

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

ans = -1

# check
for i in range(1000):
    str_i = str(i)

    if N < len(str_i):
        break

    if N == len(str_i) and False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
        ans = i
        break

print(ans)
Buggy code:
# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    SC = [list(map(int,input().split())) for i in range(M)]
    ans = []
    anst = ''
    for _ in range(N):
        ans.append(-1)
    for j in range(M):
        if ans[SC[j][0]-1] == -1  or ans[SC[j][0]-1] == SC[j][1]:
            ans[SC[j][0]-1] = SC[j][1]
        else:
            print('-1')
            return
    for k in range(N):
        if ans[k] == -1:
            if k == 0:
                ans[k] = 1
            else:
                ans[k] = 0
        anst += str(ans[k])
    if int(anst) == 0:
        print(0)
        return
    if len(str(int(anst))) != N:
        print('-1')
        return
    print(int(anst))
if __name__ == '__main__':
    main()

Fixed code:
# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    SC = [list(map(int,input().split())) for i in range(M)]
    ans = []
    anst = ''
    for _ in range(N):
        ans.append(-1)
    for j in range(M):
        if ans[SC[j][0]-1] == -1  or ans[SC[j][0]-1] == SC[j][1]:
            ans[SC[j][0]-1] = SC[j][1]
        else:
            print('-1')
            return
    for k in range(N):
        if ans[k] == -1:
            if k == 0 and N>=2:
                ans[k] = 1
            else:
                ans[k] = 0
        anst += str(ans[k])
    if len(str(int(anst))) != N:
        print('-1')
        return
    print(int(anst))
if __name__ == '__main__':
    main()
Buggy code:
N, M = map(int, input().split())

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

ans = [set() for _ in range(N)]

for i in range(M):
    ans[sc[i][0] - 1].add(sc[i][1])


ans_2 = ''
for i in range(N):
    if len(ans[i]) > 1 or ans[0] == 0:
        ans_2 = -1
        break
    else:
        if len(ans[i]) == 0:
            ans_2 += str(0)
        else:
            ans_2 += str(max(ans[i]))

print(ans_2)


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

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

ans = [set() for _ in range(N)]

for i in range(M):
    ans[sc[i][0] - 1].add(sc[i][1])


#print(ans)

ans_2 = ''
for i in range(N):
    if len(ans[i]) > 1 or (N > 1 and 0 in ans[0]):
        ans_2 = -1
        break
    else:
        if len(ans[i]) == 0:
            if i == 0 and N > 1:
                ans_2 += str(1)
            else:
                ans_2 += str(0)
        else:
            ans_2 += str(max(ans[i]))

print(ans_2)
Buggy code:
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    s-=1
    if ans[s] == -1:
        ans[s] = c
    else:
        if c == ans[s]:
            continue
        else:
            print(-1)
            sys.exit()
    if n != 1:
        if ans[s] == 0:
            print(-1)
            sys.exit()
for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
fans = ""
for i in range(n):
    fans += ans[i]
print(fans)


Fixed code:
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    s-=1
    if ans[s] == -1:
        ans[s] = c
    else:
        if c == ans[s]:
            continue
        else:
            print(-1)
            sys.exit()
if n != 1:
    if ans[0] == 0:
        print(-1)
        sys.exit()
    else:
        if ans[0] == -1:
            ans[0] = 1
        for i in range(n):
            if ans[i] == -1:
                ans[i] = 0
else:
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
fans = ""
for i in range(n):
    fans+=str(ans[i])
print(fans)
Buggy code:
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]
if n == 1:
    s,c = map(int,input().split())
    print(c)
    sys.exit()
else:
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if c == ans[s-1]:
                continue
            else:
                print(-1)
                sys.exit()
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
    for i in range(1,n+1):
        if ans[i] == -1:
            ans[i] = 0
    if ans[0] == -1:
        ans[0] = 1
    ans2 = ''
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)

Fixed code:
import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
if n == 1:
    if m == 0:
        print(0)
        sys.exit()
    else:
        for i in range(m):
            s,c = map(int,input().split())
            if ans[s-1] == -1:
                ans[s-1] = c
            else:
                if c == ans[s-1]:
                    continue
                else:
                    print(-1)
                    sys.exit()
        print(ans[0])
else:
    for i in range(m):
        s,c = map(int,input().split())
        if s-1 == 0:
            if c == 0:
                print(-1)
                sys.exit()
            else:
                if ans[s-1] == -1:
                    ans[s-1] = c
                else:
                    if c == ans[s-1]:
                        continue
                    else:
                        print(-1)
                        sys.exit()
        else:
            if ans[s-1] == -1:
                    ans[s-1] = c
            else:
                if c == ans[s-1]:
                        continue
                else:
                    print(-1)
                    sys.exit()
    if ans[0] == -1:
        ans[0] = 1
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
    ans2 = ""
    for i in range(n):
        ans2 += str(ans[i])
    print(ans2)
Buggy code:
n,m = map(int,input().split())
a = [list(map(int,input().split()))for i in range(m)]

for i in range(10**n):
    tmp = str(i)
    if len(tmp) == n:
        f = True
        for s,c in a:
            if tmp[s-1] != str(c):
                f = False
                break
            if f :
                print(i)
                exit()
print(-1)

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

for i in range(10**n):
    tmp = str(i)
    if len(tmp) == n:
        f = True
        for s,c in a:
            if tmp[s-1] != str(c):
                f = False
                break
        if f :
            print(i)
            exit()
print(-1)
Buggy code:
N, M = map(int, input().split())

if N == 1:
  ans = "*"
elif N == 2:
  ans = "**"
else: #N==3
  ans = "***"

  
ng = False
for i in range(M):
  s, c = input().split()
  s = int(s)
  if ans[s] != '*' or ans[s] != c:
    ng = True
    break
  else:
    ans[s] = c

if N == 1 and ans == "*":
  ans = "0"
if N == 2:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
if N == 3:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
  if ans[2] == "*":
    ans[2] = "0"

if ng:
  print(-1)
else:
  print(int(ans))

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

if N == 1:
  ans = ["*"]
elif N == 2:
  ans = ["*","*"]
else: #N==3
  ans = ["*","*","*"]
  
ng = False
for i in range(M):
  s, c = input().split()
  s = int(s)-1
  if ans[s] != '*' and ans[s] != c:
    ng = True
    break
  elif s==0 and c=="0" and N>1:
    ng = True
    break
  else:
    ans[s] = c

if N == 1 and ans[0] == "*":
  ans[0] = "0"
if N == 2:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
if N == 3:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
  if ans[2] == "*":
    ans[2] = "0"

if ng:
  print(-1)
else:
  print("".join(ans))
Buggy code:
N, M = map(int, input().split())

s = []
c = []
for i in range(M):
    x,y = map(int,input().split())
    s.append(x)
    c.append(y)

ans_list = [0 for i in range(N)]

for i in range(M):
    if ans_list[s[i]-1] != -1 and ans_list[s[i]-1] != c[i]:
        print(-1)
        exit()
    else:
         ans_list[s[i]-1] = c[i]
#print(ans_list)
if ans_list[0] == 0:
    print(-1)
    exit()


ans = 0
for i in range(N):
    if ans_list[i] == 0 and i != 0:
        ans_list[i] = 0
    if ans_list[i] == 0 and i == 0 and N >= 2:
        ans_list[i] = 1
    if ans_list[i] == 0 and i == 0 and N == 1:
        ans_list[i] = 0
    ans += ans_list[i] * (10**(N-i-1))

print(ans)


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

s = []
c = []
for i in range(M):
    x,y = map(int,input().split())
    s.append(x)
    c.append(y)

ans_list = [-1 for i in range(N)]

for i in range(M):
    if ans_list[s[i]-1] != -1 and ans_list[s[i]-1] != c[i]:
        print(-1)
        exit()
    else:
         ans_list[s[i]-1] = c[i]
#print(ans_list)
if ans_list[0] == 0 and N>=2:
    print(-1)
    exit()

ans = 0
for i in range(N):
    if ans_list[i] == -1 and i != 0:
        ans_list[i] = 0
    if ans_list[i] == -1 and i == 0 and N >= 2:
        ans_list[i] = 1
    if ans_list[i] == -1 and i == 0 and N == 1:
        ans_list[i] = 0
    ans += ans_list[i] * (10**(N-i-1))

print(ans)
Buggy code:
N,M = map(int,input().split())
A = [-1]*N
for _ in range(M):
    s,c = map(int,input().split())
    if A[s-1] !=-1 and A[s-1] != c:
        print(-1)
        exit()
    A[s - 1] = c
if N>1 and A[0] == -1:
    print(-1)
    exit()
ans = 0
for a in A:
    if a == -1:
        a = 0
    ans+=a
    ans*=10
print(ans//10)
        
    
    


    
    
        


Fixed code:
N,M = map(int,input().split())
A = [-1]*N
for _ in range(M):
    s,c = map(int,input().split())
    if A[s-1] !=-1 and A[s-1] != c:
        print(-1)
        exit()
    A[s - 1] = c
if N>1 and A[0] == 0:
    print(-1)
    exit()
ans = 0
if N>1 and A[0] == -1:
    A[0] = 1
for a in A:
    if a == -1:
        a = 0
    ans+=a
    ans*=10
print(ans//10)
Buggy code:
N,M = list(map(int,input().split()))
S = []
C = []
ans = [0 for i in range(3)]
fr = 0
for i in range(M):
    s = 0
    c = 0
    s,c = list(map(int,input().split()))
    S.append(s)
    C.append(c)

for i in range(M):
    if C[i] != ans[S[i]-1] and ans[S[i]-1] != 0:
        fr = 1
    else:
        ans[S[i]-1] = C[i]
if fr != 0:
    print(-1)
else:
    print(ans[0]*100 + ans[1]*10 + ans[2])

Fixed code:
N,M = list(map(int,input().split()))
S = []
C = []
ans = [11 for i in range(N)]
fr = 0
for i in range(M):
    s = 0
    c = 0
    s,c = list(map(int,input().split()))
    S.append(s)
    C.append(c)

for i in range(M):
    if C[i] != ans[S[i]-1] and ans[S[i]-1] != 11:
        fr = 1
    elif C[i] == 0 and S[i] == 1 and N > 1:
        fr = 1
    else:
        ans[S[i]-1] = C[i]

for i in range(N):
    if ans[i] == 11:
        ans[i] = 0

if ans[0] == 0 and N > 1:
    ans[0] = 1

if fr != 0:
    print(-1)
else:
    if N == 3:
        print(ans[0]*100 + ans[1]*10 + ans[2])
    elif N == 2:
        print(ans[0]*10 + ans[1])
    else:
        print(ans[0])
Buggy code:
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
  _s, _c = map(int, input().split())
  s.append(_s)
  c.append(_c)

s = [0, 0, 10, 100]
g = [10, 10, 100, 1000]
for i in range(s[n], g[n]):
  i_str = str(i)
  for j in range(m):
    if i_str[s[j]-1] != str(c[j]):
      break
  else:
    print(i)
    break
else:
  print(-1)

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

st = [0, 0, 10, 100]
go = [10, 10, 100, 1000]
for i in range(st[n], go[n]):
  i_str = str(i)
  for j in range(m):
    if i_str[s[j]-1] != str(c[j]):
      break
  else:
    print(i)
    break
else:
  print(-1)
Buggy code:
N, M = map(int, input().split())
A = []
for i in range(0, M):
    a = tuple(map(int, input().split()))
    A.append(a)
for x in range(10**(N-1)-1, 10**N):
    ans = str(x)
    flag = True
    for a in A:
        if ans[a[0]-1] != str(a[1]):
            flag = False
    if flag:
        print(x)
        exit(0)
print(-1)


Fixed code:
N, M = map(int, input().split())
A = []
for i in range(0, M):
    a = tuple(map(int, input().split()))
    A.append(a)
start = 10**(N-1)
if N == 1:
    start = 0
for x in range(start, 10**N):
    ans = str(x)
    flag = True
    for a in A:
        if ans[a[0]-1] != str(a[1]):
            flag = False
    if flag:
        print(x)
        exit(0)
print(-1)
Buggy code:
n,m = input().split()
m = int(m)
s =  [list(map(int,input().split())) for i in range(m)]
brk =0
n = int(n)
nl = [0]*n
chk = [0]*n
for i in s:
    if chk[i[0]-1] >0 and nl[i[0]-1] != i[1]:
        brk = 1
        break
    elif i == 0 and i[1] ==0:
        brk = 1
        break
    else:
        nl[i[0]-1] = i[1]
        chk[i[0]-1] += 1

if brk == 1: print("-1")
elif nl[0] == 0:
  nl[0] =1
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))
  print(fn)

else:
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))
  print(fn)

Fixed code:
n,m = input().split()
m = int(m)
s =  [list(map(int,input().split())) for i in range(m)]
brk =0
n = int(n)
nl = [0]*n
chk = [0]*n
for i in s:
    if chk[i[0]-1] >0 and nl[i[0]-1] != i[1]:
        brk = 1
        break
    elif i[0] == 1 and i[1] ==0 and n>1:
        brk = 1
        break
    else:
        nl[i[0]-1] = i[1]
        chk[i[0]-1] += 1

if brk == 1: print("-1")
elif nl[0] == 0 and n>1:
  nl[0] =1
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))
  print(fn)

else:
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))
  print(fn)
Buggy code:
import sys
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(10**n):
    s = str(i)
    c = 0
    for i in range(m):
        if n >= 2:
            if sc[i] == [1,0]:
                print(-1)
                sys.exit()
            
        if s[sc[i][0]-1] == str(sc[i][1]):
            c += 1
    
    if c == m:
        print(s)
        sys.exit()

print(-1)

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

for i in range(10**n):
    s = str(i)
    if len(s) != n:
        continue
    c = 0
    for i in range(m):
        if n >= 2:
            if sc[i] == [1,0]:
                print(-1)
                sys.exit()
            
        if s[sc[i][0]-1] == str(sc[i][1]):
            c += 1
    
    if c == m:
        print(s)
        sys.exit()

print(-1)
Buggy code:
# import numpy as np
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=['']*N
  for si,ci in zip(s,c):
    if res[si-1]== "":
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()
  for i in range(N):
    if res[i] =='':
      res[i]=str(0)
  
  print("".join(res))
  
    
if __name__=="__main__":
  main()

Fixed code:
# import numpy as np
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=['']*N
  for si,ci in zip(s,c):
    if res[si-1]== '':
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()

  
  if res[0]=='0':
    if N==1:
      print(0)
      exit()
    else:
      print(-1)
      exit()
  elif res[0]=='':
    res[0]=str(1)
   
  for i in range(N):
    if res[i]=='':
      res[i]=str(0)
  if M==0 and N==1:
    print(0)
    exit()
  print(int("".join(res)))
  
    
if __name__=="__main__":
  main()
Buggy code:
n,m=map(int,input().split())
c=[]
for i in range(m):
    c.append(list(map(int,input().split())))
ans=[-1 for i in range(n)]
cnt=0
for i in range(m):
    if ans[c[i][0]-1]==-1:
        ans[c[i][0]-1]=c[i][1]
    else:
        if ans[c[i][0]-1]==c[i][1]:
            continue
        else:
            cnt+=1
            break
if cnt!=0:
    print(-1)
else:
    if [1,0] in c and n!=1:
        print(-1)
    else:
        if ans[0]==-1 and m!=0:
            ans[0]=1
        else:
            ans[0]=0
        for i in range(n):
            if ans[i]==-1:
                ans[i]=0
            ans[i]=str(ans[i])
        aa=''.join(ans)
        print(aa)

Fixed code:
n,m=map(int,input().split())
c=[]
for i in range(m):
    c.append(list(map(int,input().split())))
ans=[-1 for i in range(n)]
cnt=0
if m==0:
    cnt=2
for i in range(m):
    if ans[c[i][0]-1]==-1:
        ans[c[i][0]-1]=c[i][1]
    else:
        if ans[c[i][0]-1]==c[i][1]:
            continue
        else:
            cnt+=1
            break
if cnt==1:
    print(-1)
elif cnt==2:
    if n==1:
        print(0)
    else:
        c='1'
        for i in range(n-1):
            c+='0'
        print(c)
else:
    if [1,0] in c and n!=1:
        print(-1)
    else:
        if ans[0]==-1:
            ans[0]=1
        for i in range(n):
            if ans[i]==-1:
                ans[i]=0
            ans[i]=str(ans[i])
        aa=''.join(ans)
        print(aa)
Buggy code:
n,m = map(int,input().split())
t = [0 for i in range(n)]
b = ""
a = True
for i in range(m):
    s,c = map(int,input().split())
    if t[s-1] != 0 and c == 0:
        a=False
    elif t[s-1] == 0 or t[s-1] == c:
        t[s-1] = c
    else:
        a=False
for i in range(n):
    b += str(t[i])
if n > 1 and b[0] == '0':
    b[0]=1
    print(b)
elif b[0] == '0':
    print(0)
elif a:
    print(b)
else:
    print(-1)

Fixed code:
n,m = map(int,input().split())
t = [0 for i in range(n)]
e = [True for i in range(n)]
b = ""
a = False
for i in range(m):
    s,c = map(int,input().split())
    if e[s-1]:
        if s == 1 and c == 0:
            a = True
            if n == 1:
                print(0)
                exit()
        else:
            t[s-1] = c
            e[s-1] = False
    else:
        if t[s-1] != c:
            a = True
for i in range(n):
    b += str(t[i])
if a:
    print(-1)
elif n > 1 and b[0] == '0':
    print(str(1)+b[1:3])
else:
    print(b)
Buggy code:
N, M = map(int, input().split())
num = [input().split() for y in range(N)]


def check(target):
    if not len(target) == N:
        return False
    for x, y in num:
        if not target[x-1] == y:
            return False
    return True


for i in range(1000):
    if check(str(i)):
        print(i)
        exit()
        
print(-1)


Fixed code:
N, M = map(int, input().split())
num = [input().split() for y in range(M)]


def check(target):
    if not len(target) == N:
        return False
    for x, y in num:
        if not target[int(x)-1] == y:
            return False
    return True


for i in range(1000):
    if check(str(i)):
        print(i)
        exit()

print(-1)