qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
x = [-1]*N
for s,c in sc:
    s -= 1
    if x[s] == -1 or x[s] == c:
        x[s] = c
    else:
        print(-1)
        exit()
if N!=1 and x[0]==0:
    print(-1)
    exit()
if x[0]==-1:
    x[0]=1
if N>=2 and x[1]==-1:
    x[1]=1
if N==3 and x[2]==-1:
    x[2]=1
print(int(''.join(list(map(str,x)))))

Fixed code:
N,M = map(int, input().split())
if N==1 and M==0:
    print(0)
    quit()
sc = [list(map(int, input().split())) for _ in range(M)]
x = [-1]*N
for s,c in sc:
    s -= 1
    if x[s] == -1 or x[s] == c:
        x[s] = c
    else:
        print(-1)
        quit()
if N!=1 and x[0]==0:
    print(-1)
    quit()
if x[0]==-1:
    x[0]=1
if N>=2 and x[1]==-1:
    x[1]=0
if N==3 and x[2]==-1:
    x[2]=0
print(int(''.join(list(map(str,x)))))
Buggy code:
n, m = map(int, input().split())
s = [0]*m
c = [0]*m
num = ['']*n
for i in range(m):
    s[i], c[i] = map(int, input().split())
    if s[i]==1 and c[i]==0:
        print(-1)
        exit()
    elif num[s[i]-1] == '':
        num[s[i]-1] = c[i]
    elif num[s[i]-1] != c[i]:
        print(-1)
        exit()
for i in range(m):
    if num[i]=='':
        num[i] = 1
print(''.join(map(str,num)))

Fixed code:
n, m = map(int, input().split())
num = ["A"] * n
for i in range(m):
    s, c = map(int, input().split())
    if n>1 and s == 1 and c == 0:
        print(-1)
        exit()
    elif num[s - 1] != "A" and num[s - 1] != c:
        print(-1)
        exit()
    num[s - 1] = c

for j in range(n):
    if num[j] == "A":
        num[j] = 0
    if n>1 and num[0] == 0:
        num[0] = 1
print(int("".join(map(str, num))))
Buggy code:
N,M=map(int,input().split())
x=[-1]*N
for i in range(M):
    s,c=map(int,input().split())
    if x[s-1]==-1:
        x[s-1]=c
    elif x[s-1]!=c:
        print(-1)
        exit()
for a in range(N):
    if x[a]==-1:
        x[a]=0
print(*x,sep="")

Fixed code:
N,M=map(int,input().split())
x=[-1]*N
for i in range(M):
    s,c=map(int,input().split())
    if x[s-1]==-1:
        x[s-1]=c
    elif x[s-1]!=c:
        print(-1)
        exit()
if N>=2:
    if x[0]==0:
        print(-1)
        exit()
    if x[0]==-1:
        x[0]=1
else:
    if x[0]==-1:
        x[0]=0
for a in range(N):
    if x[a]==-1:
        x[a]=0

print(*x,sep="")
Buggy code:
N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]

import sys
 
number = [[i for i in range(10)] for i in range(N)]
number[0].pop(0)

n_count = [0]*N
 
for i in range(M):
    if n_count[sc[i][0]-1] > 0:
        if sc[i][1] != number[sc[i][0]-1][-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1].append(sc[i][1])
    n_count[sc[i][0]-1] += 1

for i in range(N):
    if n_count[i] > 0:
        print(number[i][-1],end='')
    else:
        print(min(number[i]),end='')

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

import sys

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
 
number = [[i for i in range(10)] for i in range(N)]
number[0].pop(0)

n_count = [0]*N
 
for i in range(M):
    if n_count[sc[i][0]-1] > 0:
        if sc[i][1] != number[sc[i][0]-1][-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1].append(sc[i][1])
    n_count[sc[i][0]-1] += 1
    
if N != 1 and number[0][-1] == 0:
    print(-1)
    sys.exit()

for i in range(N):
    if n_count[i] > 0:
        print(number[i][-1],end='')
    else:
        print(min(number[i]),end='')
Buggy code:
n, m = [int(i) for i in input().split(' ')]
c_list = []
for i in range(m):
    c_list.append([int(i) for i in input().split(' ')])
number = [-1 for i in range(n)]
for line in c_list:
    if number[line[0] - 1] == -1:
        number[line[0] - 1] = line[1]
    else:
        if number[line[0] - 1] == line[1]:
            continue
        else:
            print("-1")
            break
else:
    if number[0] == 0 and len(number) != 1:
        number[0] == 1
    else:
        for index in number:
            if index == -1:
                index = 0
            print(index, end="")

Fixed code:
n, m = [int(i) for i in input().split(' ')]
c_list = []
for i in range(m):
    c_list.append([int(i) for i in input().split(' ')])
number = [-1 for i in range(n)]
for line in c_list:
    if number[line[0] - 1] == -1:
        number[line[0] - 1] = line[1]
    else:
        if number[line[0] - 1] == line[1]:
            continue
        else:
            print("-1")
            break
else:
    if number[0] == 0:
        if len(number) != 1:
            print("-1")
        else:
            print("0")
    else:
        for i, index in enumerate(number):
            if index == -1:
                if i == 0 and len(number) != 1:
                    index = 1
                else:
                    index = 0
            print(index, end="")
Buggy code:
n, m = map(int, input().split())
if m == 0:
  print(-1)
  exit()
digit = [None] * n
for ind in range(m):
  s, c = map(int, input().split())
  if digit[s-1] == None:
    digit[s-1] = c
  elif digit[s-1] != c:
    print(-1)
    exit()
#print(digit)
nums = [0] * n
for ind, num in enumerate(digit):
  if num != None:
    nums[ind] = num
#print(nums)
if n > 0 and nums[0] == 0:
  print(-1)
result = 0
for ind, num in enumerate(nums):
  result += 10**(n-ind-1) * num
print(result)

Fixed code:
n, m = map(int, input().split())
if n == 1 and m == 0:
  print(0)
  exit()
digit = [None] * n
for ind in range(m):
  s, c = map(int, input().split())
  if digit[s-1] == None:
    digit[s-1] = c
  elif digit[s-1] != c:
    print("-1")
    exit()
#print(digit)
if n > 1 and digit[0] == 0:
  print("-1")
  exit()
nums = [0] * n
for ind, num in enumerate(digit):
  if ind == 0 and num == None:
    nums[ind] = 1
  if num != None:
    nums[ind] = num
result = 0
for ind, num in enumerate(nums):
  result += 10**(n-ind-1) * num
print(result)
Buggy code:
n, m = map(int, input().split())
ans = ["-1" for i in range(n)]
for i in range(m):
    s, c = input().split()
    s = int(s)
    if (s == 1 and c == '0'):
        print(-1)
        exit()
    if ans[s-1] == "-1" :
        ans[s-1] = c
    else:
        if ans[s-1] != c :
            print(-1)
            exit()
print(("".join(ans)).replace("-1", "1"))


Fixed code:
n, m = map(int, input().split())
ans = ["-1" for i in range(n)]
for i in range(m):
    s, c = input().split()
    s = int(s)
    if s == 1 and c == '0' and n != 1:
        print(-1)
        exit()
    if ans[s-1] == "-1":
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            print(-1)
            exit()
if ans[0] == '-1':
    ans[0] = "1"
if m == 0:
    ans[n-1] = "0"
print(("".join(ans)).replace("-1","0"))
Buggy code:
n, m = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(m)]

ans = [-1]*n
flag = False

for s, c in X:
    if ans[s-1]>=0 and ans[s-1]!=c:
        flag = False
    if n > 1 and s == 1 and c == 0:
        flag = False
    else:
        ans[s-1] = c

if flag:
    print(-1)
    exit(0)

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

print(*ans, sep="")

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

ans = [-1]*n
flag = False

for s, c in X:
    if ans[s-1] >= 0 and ans[s-1] != c:
        flag = True
    if n > 1 and s == 1 and c == 0:
        flag = True
    else:
        ans[s-1] = c

if flag:
    print(-1)
    exit(0)

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

print(*ans, sep="")
Buggy code:
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
temp = [-1] * n
ans = -1

for i in sc:
    if temp[i[0]-1] != -1 and temp[i[0]-1] != i[1]:
        print(-1)
        exit()
    temp[i[0]-1] = i[1]

if n == 1:
    mini = 0
    maxi = 10
if n == 2:
    mini = 10
    maxi = 100
if n == 3:
    mini = 100
    maxi = 1000

print(mini,maxi)
for i in range(mini,maxi):
    s = str(i)
    ok = True
    for j in sc:
        if s[j[0]-1] != str(j[1]):
            ok = False
    if ok:
        ans = i
        print(ans)
        exit()

print(ans)

Fixed code:
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
temp = [-1] * n
ans = -1

for i in sc:
    if temp[i[0]-1] != -1 and temp[i[0]-1] != i[1]:
        print(-1)
        exit()
    temp[i[0]-1] = i[1]

if n == 1:
    mini = 0
    maxi = 10
if n == 2:
    mini = 10
    maxi = 100
if n == 3:
    mini = 100
    maxi = 1000

for i in range(mini,maxi):
    s = str(i)
    ok = True
    for j in sc:
        if s[j[0]-1] != str(j[1]):
            ok = False
    if ok:
        ans = i
        print(ans)
        exit()

print(ans)
Buggy code:
n, m = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(m)]
if n == 1:
    for i in range(10):
        tmp = str(i)
        flag = True
    for j in range(m):
        if tmp[arr[j][0]-1] != str(arr[j][1]):
            flag = False
    if flag:
        print(i)
        break
    else:
        print(-1)
else:
    for i in range(10**(n-1),10**n):
        tmp = str(i)
        flag = True
    for j in range(m):
        if tmp[arr[j][0]-1] != str(arr[j][1]):
            flag = False
    if flag:
        print(i)
        break
    else:
        print(-1)

Fixed code:
n, m = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(m)]
if n == 1:
    for i in range(10):
        tmp = str(i)
        flag = True
        for j in range(m):
            if tmp[arr[j][0]-1] != str(arr[j][1]):
                flag = False
        if flag:
            print(i)
            exit()
    print(-1)
else:
    for i in range(10**(n-1),10**n):
        tmp = str(i)
        flag = True
        for j in range(m):
            if tmp[arr[j][0]-1] != str(arr[j][1]):
                flag = False
        if flag:
            print(i)
            exit()
    print(-1)
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)
for n in range(1000):
    if len(str(n))==N:
        count = 0        
        if n==0:
            l=[0]
        else:
            l = []
            while n > 0:
                l.append(n%10)
                n //= 10
            l.reverse()
                
        for i in range(M):     
            if(l[S[i]-1] == C[i]):
                count += 1
            
        if count == M:
            break
else:
    n=-1
    
print(n)            

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)
for n in range(1000):
    m=n
    if len(str(n))==N:
        count = 0        
        if n==0:
            l=[0]
        else:
            l = []
            while m > 0:
                l.append(m%10)
                m //= 10
            l.reverse()
                
        for i in range(M):     
            if(l[S[i]-1] == C[i]):
                count += 1
            
        if count == M:
            break
else:
    n=-1
    
print(n)
Buggy code:
n,m=map(int, input().split())
list1=[list(map(int,input().split())) for i in range(m)]

if m

ans=['x']*n
non=0
for i in range(m):
    if ans[list1[i][0]-1]!='x':
        if int(ans[list1[i][0]-1])==list1[i][1]:
            continue
        else:
            non=-1
            break
    else:
        ans[list1[i][0]-1]=str(list1[i][1])

if non==-1:
    print(-1)
else:
    if ans[0]=='0':
        print(-1)
    else:
        if 'x' in ans:
            if ans[0]=='x':
                ans[0]='1'
            else:
                for i in range(n):
                    if ans[i]=='x':
                        ans[i]='0'
        K=''
        for i in range(n):
            K+=ans[i]
        print(int(K))

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

ans=['x']*n
non=0
for i in range(m):
    if ans[list1[i][0]-1]!='x':
        if int(ans[list1[i][0]-1])==list1[i][1]:
            continue
        else:
            non=-1
            break
    else:
        ans[list1[i][0]-1]=str(list1[i][1])

if non==-1:
    print(-1)
else:
    if ans[0]=='0' and n!=1:
        print(-1)
    else:
        if 'x' in ans:
            if ans[0]=='x' and n!=1:
                ans[0]='1'
            for i in range(n):
                if ans[i]=='x':
                    ans[i]='0'
        K=''
        for i in range(n):
            K+=ans[i]
        print(int(K))
Buggy code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, m = LI()
ret = [''] * n
for _ in range(m):
    s, c = LI()
    if ret[s - 1] and ret[s - 1] != str(c):
        print(-1)
        exit()
    elif s == 1 and not 0 and n != 1:
        print(-1)
        exit()
    else:
        ret[s - 1] = str(c)

for i in range(n):
    if not ret[i]:
        ret[i] = '0' if i or not n else '1'

ans = ''.join(ret)
print(ans)

Fixed code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, m = LI()
ret = [''] * n
for _ in range(m):
    s, c = LI()
    if ret[s - 1] and ret[s - 1] != str(c):
        print(-1)
        exit()
    elif s == 1 and c == 0 and n != 1:
        print(-1)
        exit()
    else:
        ret[s - 1] = str(c)

for i in range(n):
    if not ret[i]:
        ret[i] = '0' if i or n == 1 else '1'

ans = ''.join(ret)
print(ans)
Buggy code:
def main():
    n, m = map(int, input().split())
    nums = [10]*n
    result = None
    for _ in range(m):
        s, e = map(int, input().split())
        if nums[s-1] == 10:
            nums[s - 1] = e
        elif nums[s-1] != e:
            result = '-1'
            break

    for i in range(n):
        if nums[i] == 10:
            nums[i] = 0
    if nums[0] == 0:
        nums[0] = 1

    if result == '-1':
        print('-1')
    else:
        print(''.join(map(str, nums)))


if __name__ == "__main__":
    main()


Fixed code:
def main():
    n, m = map(int, input().split())
    nums = [10]*n
    result = None
    for _ in range(m):
        s, e = map(int, input().split())
        if nums[s-1] == 10:
            nums[s - 1] = e
        else:
            if nums[s - 1] != e:
                result = '-1'
                break

    for i in range(n):
        if i == 0 and nums[i] == 10 and len(nums) > 1:
            nums[i] = 1
        elif nums[i] == 10:
            nums[i] = 0

    if result == '-1':
        print('-1')
    elif nums[0] == 0 and len(nums) > 1:
        print('-1')
    else:
        print(''.join(map(str, nums)))


if __name__ == "__main__":
    main()
Buggy code:
N, M=map(int, input().split())

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

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0:
  ans=False
    
if ans:
  for i in range(N):
    if num[i]=="a":
      print(1, end="")
    else:
      print(num[i], end="")
else:
  print(-1)
  
         

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

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

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0 and len(num)>1:
  ans=False
    
if ans:
  if len(num)==1:
    if num[0]=="a":
      print(0)
    else:
      print(num[0])
  else:
    for i in range(N):
      if num[i]=="a":
        if i==0:
          print(1, end="")
        else:
          print(0, end="")
      else:
        print(num[i], end="")
else:
  print(-1)
Buggy code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]

ans = -1
for i in range(10 ** (n - 1) - 1, 10 ** n):
    tmp = str(i)
    flg = False
    for l in lst:
        if tmp[l[0] - 1] == str(l[1]):
            flg = True
            break
    if flg == True:
        ans = i
        break

print(ans)

Fixed code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for i in range(10 ** n):
    tmp = str(i)
    if len(tmp) == n:
        flg = True
        for l in lst:
            if tmp[l[0] - 1] != str(l[1]):
                flg = False
                break
        if flg == True:
            ans = i
            break
print(ans)
Buggy code:
N, M = map(int, input().split())
q = [list(map(int, input().split())) for i in range(M)]

ans = -1
for i in range(10 ** (N-1), 10 ** N + 1):
  flag = True
  for j in range(M):
    try:
      if str(i)[q[j][0] - 1] != q[j][1]:
        flag = False
    except:
      flag = False
      break
      
  if flag:
    ans = i
    break
    
print(ans)


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

ans = -1
if N == 1:
  s = 0
else:
  s = 10 ** (N - 1)
for i in range(s, 10 ** N + 1):

  flag = True
  for j in range(M):
    try:
      if str(i)[q[j][0] - 1] != str(q[j][1]):
        flag = False
    except:
      flag = False
      break
      
  if flag:
    ans = i
    break
    
print(ans)
Buggy code:
N,M=map(int,input().split())
ans=[-1]*N
sc=[list(map(int,input().split())) for i in range(M)]
cnt=0
for i in range(M):
    if ans[sc[i][0]-1]==-1:
        ans[sc[i][0]-1]=sc[i][1]
    else:
        if ans[sc[i][0]-1]!=sc[i][1]:
            cnt+=1
if cnt>0:
    print(-1)
else:
    s=''
    for i in range(N):
        if ans[i]==-1:
            if i==0:
                ans[i]=1
            else:
                ans[i]=0
        s+=str(ans[i])
    print(int(s))

Fixed code:
N,M=map(int,input().split())
ans=[-1]*N
sc=[list(map(int,input().split())) for i in range(M)]
cnt=0
for i in range(M):
    if ans[sc[i][0]-1]==-1:
        ans[sc[i][0]-1]=sc[i][1]
    else:
        if ans[sc[i][0]-1]!=sc[i][1]:
            cnt+=1
if cnt>0:
    print(-1)
elif ans[0]==0 and N!=1:
    print(-1)
else:
    s=''
    for i in range(N):
        if N!=1:
            if ans[0]==-1:
                ans[0]=1
            if ans[i]==-1 and i!=0:
                ans[i]=0
        else:
            if ans[0]==-1:
                ans[0]=0
        s+=str(ans[i])
    print(int(s))
Buggy code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()

data = []
for i in range(M):
    s,c = input_int()
    data.append([s,c])

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

def solve(N, data):
    mins = 100000000000
    for i in range(10**N):

        temp = str(i)
        flg = True
        for d in data:
            if temp[d[0]-1] != str(d[1]) and len(temp)==N:
                flg = False
                break
        if flg==True:
            return temp
    return -1

output = solve(N,data)
print(output)

Fixed code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()

data = []
for i in range(M):
    s,c = input_int()
    data.append([s,c])

def solve(N, data):
    mins = 100000000000
    for i in range(10**N):

        temp = str(i)
        flg = True
        if len(temp)==N:
            for d in data:
                if temp[d[0]-1] != str(d[1]):
                    flg = False
                    break
            if flg==True:
                return temp
    return -1

output = solve(N,data)
print(output)
Buggy code:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''
tmp = []
ans = -1
sc2 = []

for i in range(M):
    if cnt[sc[i][0] - 1] == 0:
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
        sc2.append([sc[i][0], sc[i][1]])
    else:
        if chk[sc[i][0] - 1] != sc[i][1]:
            print(-1)
            exit()

for i in range(0, 1000):
    cnt = 0
    for j in range(len(sc2)):
        if len(str(i)) < N:
            break
        if str(i)[sc2[j][0] - 1] == str(sc2[j][1]):
            cnt += 1

    if cnt >= len(sc2):
        ans = i
        break

print(0)

Fixed code:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''
ans = -1
sc2 = []

if M == 0:
    if N == 1:
        print(0)
        exit()
    else:
        tmp = ''
        for i in range(N):
            if i == 0:
                tmp += '1'
            else:
                tmp += '0'
        print(int(tmp))
        exit()
for i in range(M):
    if cnt[sc[i][0] - 1] == 0:
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
        sc2.append([sc[i][0], sc[i][1]])
    else:
        if chk[sc[i][0] - 1] != sc[i][1]:
            print(-1)
            exit()

for i in range(1000):
    cnt = 0
    for j in range(len(sc2)):
        if len(str(i)) < N:
            break
        if str(i)[sc2[j][0] - 1] == str(sc2[j][1]):
            cnt += 1

    if cnt >= len(sc2):
        ans = i
        break

print(ans)
Buggy code:
N, M = map(int, input().split())
guess = [-1] * N

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

if len(guess) > 1 and guess[0] == -1:
  guess[0] = 1
for i in range(len(guess)):
  if guess[i] == -1:
    guess[i] = 0
    
res = map(str, guess)
print(''.join(res))

Fixed code:
N, M = map(int, input().split())
guess = [-1] * N

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

if len(guess) > 1 and guess[0] == -1:
  guess[0] = 1
for i in range(len(guess)):
  if guess[i] == -1:
    guess[i] = 0
    
res = map(str, guess)
print(''.join(res))