qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
n, m = map(int, input().split())
isExist=True
li2 = [[''] for i in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if (li2[s - 1][0] != '' and li2[s - 1][0] != c):
        isExist = False
    elif(s == 1 and c == 0):
            isExist = False
    else:
        li2[s - 1][0] = c
ans=''
if (not isExist):
        print(-1)
        sys.exit()
    else:
        print(0)
        sys.exit()
for i in range(n):
    if (li2[0][0] == ''):
        li2[0][0]=1
    if (li2[i][0] == ''):
        li2[i][0] = 0
for i in range(n):
    ans += str(li2[i][0])
if (n == 1 and m == 0):
    ans=0
print(int(ans))

Fixed code:
import sys
n, m = map(int, input().split())
isExist = True
isExist2=True
li2 = [[''] for i in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if (li2[s - 1][0] != '' and li2[s - 1][0] != c):
        isExist = False
    elif(s == 1 and c == 0):
            isExist2 = False
    else:
        li2[s - 1][0] = c
ans=''
if (not isExist):
        print(-1)
        sys.exit()
if (not isExist2):
    if (n == 1):
        print(0)
        sys.exit()
    else:
        print(-1)
        sys.exit()
for i in range(n):
    if (li2[0][0] == ''):
        li2[0][0]=1
    if (li2[i][0] == ''):
        li2[i][0] = 0
for i in range(n):
    ans += str(li2[i][0])
if (n == 1 and m == 0):
    ans=0
print(int(ans))
Buggy code:
N, M = map(int, input().split())
sc_list = []
for i in range(M):
    s, c = map(int, input().split())
    sc_list.append([s,c])
ans = ""
flag = 0
num_slot = [-1 for i in range(N)]
for lists in sc_list:
    if num_slot[lists[0]-1] != -1 and num_slot[lists[0]-1] != lists[1]:
        print(-1)
        flag = 1
        break
    else:
        num_slot[lists[0]-1] = lists[1]
if flag == 0:
    for i in range(N):
        if num_slot[i] != -1:
            ans += str(num_slot[i])
        else:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
    if ans[0] == "0":
        print(-1)
    else:
        print(int(ans))
else:
    print(-1)

Fixed code:
N, M = map(int, input().split())
sc_list = []
for i in range(M):
    s, c = map(int, input().split())
    sc_list.append([s,c])
ans = ""
flag = 0
num_slot = ["X" for i in range(N)]
for lists in sc_list:
    if num_slot[lists[0]-1] != "X" and num_slot[lists[0]-1] != lists[1]:
        print(-1)
        flag = 1
        break
    else:
        num_slot[lists[0]-1] = lists[1]
if flag == 0:
    for i in range(N):
        if num_slot[i] != "X":
            ans += str(num_slot[i])
        else:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
    if ans[0] == "0" and ans != "0":
        print(-1)
    elif N == 1 and M == 0:
        print(0)
    else:
        print(int(ans))
Buggy code:
n,m=map(int,input().split())
q=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    i=str(i)
    f=1
    for j in q:
        if i[j[0]-1]!=str(j[1]):
            f=0
            break
    if f:
        print(i)
        exit()
print("-1")

Fixed code:
n,m=map(int,input().split())
q=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    i=str(i)
    if len(i)!=n:
        continue
    f=1
    for j in q:
        if i[j[0]-1]!=str(j[1]):
            f=0
            break
    if f:
        print(i)
        exit()
print("-1")
Buggy code:
N,M=map(int,input().split())

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

flg=True
num=[-1 for i in range(N)]

for i in range(M):
    if num[pos[i][0]-1]==-1 or num[pos[i][0]]==pos[i][1]:
        if i!=0 or pos[i][1]!=0:
            num[pos[i][0]-1]=pos[i][1]
        else:
            flg=False
    else:
        flg=False

for i in range(len(num)):
    if num[i]==-1:
        if i==0:
            num[i]=1
        else:
            num[i]=0

ans=0
for i in range(N):
    ans+=num[i]*10**(N-i-1)

if flg:
    print(ans)
else:
    print("-1")

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

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

flg=True
num=[-1 for i in range(N)]

for i in range(M):
    if num[pos[i][0]-1]==-1 or num[pos[i][0]-1]==pos[i][1]:
        if pos[i][0]-1!=0 or pos[i][1]!=0:
            num[pos[i][0]-1]=pos[i][1]
        else:
            if N==1:
                num[pos[i][0]-1]=pos[i][1]
            else:
                flg=False
    else:
        flg=False

for i in range(len(num)):
    if num[i]==-1:
        if i==0:
            if N==1:
                num[i]=0
            else:
                num[i]=1
        else:
            num[i]=0

ans=0
for i in range(N):
    ans+=num[i]*10**(N-i-1)

if flg:
    print(ans)
else:
    print("-1")
Buggy code:
#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
print(sc)
ans = []
for i in range(10**(n-1),10**n):
    cnt = 0
    seq = str(i)
    for j in range(m):
        if seq[int(sc[j][0])-1] == sc[j][1]:
            cnt += 1
    if cnt == m:
        ans.append(i)
if cnt == 0:
    print('-1')
else:
    print(min(ans))

Fixed code:
#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
ans =[]

if n == 1:
    if len(sc)== 0:
        print('0')
    else:
        ans = []
        for i in range(m):
            ans.append(sc[i][1])
        if len(set(ans)) == 1:
            print(ans[0])
        else:
            print('-1')
    
else:
    for i in range(10**(n-1),10**n):
        cnt = 0
        seq = str(i)
        for j in range(m):
            if seq[int(sc[j][0])-1] == sc[j][1]:
                cnt += 1
        if cnt == m:
            ans.append(i)
        
    if len(ans) == 0:
        print('-1')
    else:
        print(min(ans))
Buggy code:
N,M = list(map(int,input().split()))
ans = [-1 for i in range(N)]

for i in range(M):
  S,C = list(map(int,input().split()))
  if N != 1 and C == 0 and S == 1:
    print('-1')
    exit()
  if ans[S-1] == C:
    continue
  elif ans[S-1] != -1:
    print('-1')
    exit()
  ans[S-1] = C
  
for i in range(N):
  if ans[i] == -1:
    ans[i] = str(0)
  ans[i] = str(ans[i])

print(ans)
print("".join(ans))

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

if N == 1 and M == 0:
  print(0)
  exit()
if M == 0:
  ans[0] = str(1)
  for i in range(1,N):
    ans[i] = str(0)
  print("".join(ans))
  exit()

for i in range(M):
  S,C = list(map(int,input().split()))
  if N != 1 and C == 0 and S == 1:
    print('-1')
    exit()
  if ans[S-1] == C:
    continue
  elif ans[S-1] != -1:
    print('-1')
    exit()
  ans[S-1] = C
  
for i in range(N):
  if ans[i] == -1:
    if i == 0:
      ans[i] = 1
    else:
      ans[i] = str(0)
  ans[i] = str(ans[i])

print("".join(ans))
Buggy code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
D = [-1] * N

for m in range(M):
    s, c = [int(x) for x in input().strip().split()]
    if D[s-1] == -1:
        D[s-1] = c
        continue
    if D[s-1] == c:
        continue
    print(-1)
    exit()

if N > 1:
    if D[0] == 0:
        print(-1)
        exit()
    for n in range(1, N):
        if D[n] == -1:
            D[n] = 0

print(D)
ans = ''
for i in range(N):
    ans += str(D[i])

print(int(ans))


Fixed code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
D = [-1] * N

for m in range(M):
    s, c = [int(x) for x in input().strip().split()]
    if D[s-1] == -1:
        D[s-1] = c
        continue
    if D[s-1] == c:
        continue
    print(-1)
    exit()

if N > 1:
    if D[0] == -1:
        D[0] = 1
    if D[0] == 0:
        print(-1)
        exit()
    for n in range(1, N):
        if D[n] == -1:
            D[n] = 0
if N == 1:
    if D[0] == -1:
        print(0)
        exit()

ans = ''
for i in range(N):
    ans += str(D[i])

print(int(ans))
Buggy code:
N, M = map(int, input().split())
query = [list(input().split()) for _ in range(M)]

for num in range(10**N):
    if len(str(num)) != N:
        continue
    else:
        cnt = 0
        s = str(num)
        for sc in query:
            if s[int(sc[0])-1] == sc[1]:
                cnt += 1
        if cnt == M:
            ans = num
            break
print(ans)

Fixed code:
N, M = map(int, input().split())
query = [list(input().split()) for _ in range(M)]
ans = -1
for num in range(10**N):
    if len(str(num)) != N:
        continue
    else:
        cnt = 0
        s = str(num)
        for sc in query:
            if s[int(sc[0])-1] == sc[1]:
                cnt += 1
        if cnt == M:
            ans = num
            break
print(ans)
Buggy code:
N,M = map(int, input().split())
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i]= map(int, input().split())
    
n=[-1]*N
w=True
for i in range(M):
    if n[s[i]-1]==-1:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]==c[i]:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]!=c[i]:
        w=False
if  n[0]==0 and N!=1:
    w=False
if  n[0]==-1 and N!=1:
    n[0]=1
if n[0]==-1 and N==1:
    n[0]=0
if N=3:
    if n[1]==-1:
        n[1]=0
    if n[2]==-1:
        n[2]=0
if N=2:
    if n[1]==-1:
        n[1]=0
num=''
for i in n:
    num+=str(i)
if w:
    print(num)
else:
    print('-1')

Fixed code:
N,M = map(int, input().split())
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i]= map(int, input().split())
    
n=[-1]*N
w=True
for i in range(M):
    if n[s[i]-1]==-1:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]==c[i]:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]!=c[i]:
        w=False
if  n[0]==0 and N!=1:
    w=False
if  n[0]==-1 and N!=1:
    n[0]=1
if n[0]==-1 and N==1:
    n[0]=0
if N==3:
    if n[1]==-1:
        n[1]=0
    if n[2]==-1:
        n[2]=0
if N==2:
    if n[1]==-1:
        n[1]=0
num=''
for i in n:
    num+=str(i)
if w:
    print(num)
else:
    print('-1')
Buggy code:
N,M = map(int,input().split())
SC = [tuple(map(int,input().split())) for i in range(M)]

if N==1:
    r = range(10)
elif N==2:
    r = range(10,100)
else:
    r = range(100,1000)
for n in r:
    print(n)
    n = str(n)
    for s,c in SC:
       #print("s=",s,"c",c)
        if n[s-1] != str(c):
            break
    else:
        print(n)
        exit()
print(-1)


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

if N==1:
    r = range(10)
elif N==2:
    r = range(10,100)
else:
    r = range(100,1000)
for n in r:
    #print(n)
    n = str(n)
    for s,c in SC:
       #print("s=",s,"c",c)
        if n[s-1] != str(c):
            break
    else:
        print(n)
        exit()
print(-1)
Buggy code:
def main():
    n, m = map(int, input().split())
    num = [set() for _ in range(m)]
    ans = ""
    for _ in range(m):
        s, v = input().split()
        num[int(s)-1].add(v)
    for i in num[:-1]:
        if len(i) == 0:
            ans += "0"
        elif len(i) == 1:
            ans += list(i)[0]
        else:
            print(-1)
            return
    if len(num[-1]) > 1:
        print(-1)
        return
    if len(num[-1]) == 1:
        ans += list(num[-1])[0]
    else:
        if n == 1:
            ans += "0"
        else:
            ans += "1"
    print(ans)

if __name__ == "__main__":
    main()

Fixed code:
def main():
    n, m = map(int, input().split())
    num = [set() for _ in range(n)]
    ans = ""
    for _ in range(m):
        s, v = input().split()
        num[int(s)-1].add(v)
    if len(num[0]) > 1 or (n > 1 and num[0] and list(num[0])[0] == "0"):
        print(-1)
        return
    if len(num[0]) == 1:
        ans += list(num[0])[0]
    else:
        if n == 1:
            ans += "0"
        else:
            ans += "1"
    for i in num[1:]:
        if len(i) == 0:
            ans += "0"
        elif len(i) == 1:
            ans += list(i)[0]
        else:
            print(-1)
            return
    print(ans)

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

t=[-1]*N
for i in range(m):
  s,c=map(int,input().split())
  s-=1
  if t[s] != -1 and t[s] != c:
    print(-1)
    exit()
  t[s]=c

if n != 1:
  if t[0] == 0:
    print(-1)
    exit()
  if t[0] == -1:
    t[0]=1
  for i in range(1,n):
    if t[i] == -1:
      t[i] = 0
else:
  if t[0] == -1:
    t[0] = 0
print(''.join(map(str,t)))

Fixed code:
n,m=map(int,input().split())

t=[-1]*n
for i in range(m):
  s,c=map(int,input().split())
  s-=1
  if t[s] != -1 and t[s] != c:
    print(-1)
    exit()
  t[s]=c

if n != 1:
  if t[0] == 0:
    print(-1)
    exit()
  if t[0] == -1:
    t[0]=1
  for i in range(1,n):
    if t[i] == -1:
      t[i] = 0
else:
  if t[0] == -1:
    t[0] = 0
print(''.join(map(str,t)))
Buggy code:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

for i in range(10**n):
  i2=str(i)
  if len(i2)==n and all([i2[s-1]==str(c) for s,c in sc]):
      print(i2)
      break
print(-1)

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

for i in range(10**n):
  i2=str(i)
  if len(i2)==n and all([i2[s-1]==str(c) for s,c in sc]):
      print(i2)
      exit()
print(-1)
Buggy code:
n, m = map(int, input().split())

if n == 1 and m == 0:
  print(0)
  exit()
  
ans = list(' '*n)

for i in range(m):
  a, b = map(int, input().split())
  
  if a==1 and b ==0:
    print(-1)
    exit()
  if ans[a-1] != ' ' and ans[a-1] != str(b):
    print(-1)
    exit()
    
  ans[a-1] = str(b)


if ans[0] == ' ':
  ans[0] = '1'
ans = ''.join(ans)
print(ans)
print(int(ans.replace(' ', '0')))


Fixed code:
n, m = map(int, input().split())

ans = list(' '*n)

for i in range(m):
  a, b = map(int, input().split())
  
  if n != 1 and a==1 and b ==0:
    print(-1)
    exit()
  if ans[a-1] != ' ' and ans[a-1] != str(b):
    print(-1)
    exit()
    
  ans[a-1] = str(b)

if ans[0] == ' ' and n != 1:
  ans[0] = '1'
ans = ''.join(ans)

print(int(ans.replace(' ', '0')))
Buggy code:
N,M = [int(i) for i in input().split(" ")]
check_list = []

for _ in range(M):
    check_list.append([int(i) for i in input().split(" ")])

for i in range(10 ** (N + 1)):
    i = str(i)
    for j in check_list:
        if i[j[0] - 1] != str(j[1]):
            break
        else:
            continue
    else:
        print(i)
        break
else:
    print(-1)

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

for _ in range(M):
    check_list.append([int(i) for i in input().split(" ")])

for i in range(10 ** N):
    i = str(i)
    if len(i) != N:
        continue

    for j in check_list:
        if i[j[0] - 1] != str(j[1]):
            break
        else:
            continue
    else:
        print(i)
        break
else:
    print(-1)
Buggy code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    SC = [il() for _ in range(M)]
    mi = pow(10, N - 1)-1
    mx = pow(10, N)

    for n in range(mi, mx):
        isSC = True
        for s, c in SC:
            if str(n)[s - 1] != str(c):
                isSC = False

        if isSC:
            print(n)
            exit()

    print(-1)


if __name__ == '__main__':
    main()


Fixed code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    SC = [il() for _ in range(M)]
    mx = pow(10, N)

    for n in range(0, mx):
        if len(str(n)) != N: continue
        isSC = True
        for s, c in SC:
            if str(n)[s - 1] != str(c):
                isSC = False

        if isSC:
            print(n)
            exit()

    print(-1)


if __name__ == '__main__':
    main()
Buggy code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.readline().split()))
    lines = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

    print(lines)
    ret = -1
    for n in range(0, pow(10, N)):
        if len(str(n)) != N:
            continue
        flg = True
        for s, c in lines:
            if str(n)[s - 1] != str(c):
                flg = False

        if flg:
            ret = n
            break

    print(ret)


if __name__ == '__main__':
    main()


Fixed code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.readline().split()))
    lines = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

    ret = -1
    for n in range(0, pow(10, N)):
        if len(str(n)) != N:
            continue
        flg = True
        for s, c in lines:
            if str(n)[s - 1] != str(c):
                flg = False

        if flg:
            ret = n
            break

    print(ret)


if __name__ == '__main__':
    main()
Buggy code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

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

for i in range(10**(N-1),10**N):
    #print(i)
    temp=list(str(i))
    judge=True
    for s,t in l:
        if temp[N-s]!=str(t):
            judge=False
    if judge:
        print(i)
        exit()

print(-1)


Fixed code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

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

for i in range(10**(N-1) if N!=1 else 0,10**N):
    temp=list(str(i))
    judge=True
    for s,t in l:
        if temp[s-1]!=str(t):
            judge=False
    if judge:
        print(i)
        exit()
        
print(-1)
Buggy code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M = MI()
	NUM = [-1]*N
	ch = True
	for i in range(M):
		s,c = MI()
		s = s-1
		if(NUM[s]!=-1 and NUM[s]!=c):
			ch = False
		NUM[s]=c
	if(NUM[0]==0 and N==1):
		ch=False
	if(ch==False):
		print(-1)
	else:
		ans = 0
		t = 10**(N-1)
		for i in range(N):
			if(NUM[i]==-1 and (i==0 or N==1)):
				ans += t
			elif(NUM[i]!=-1):
				ans += (t * NUM[i])
			t //= 10

		print(ans)




if __name__ == '__main__':
	main()

Fixed code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M = MI()
	NUM = [-1]*N
	ch = True
	for i in range(M):
		s,c = MI()
		s = s-1
		if(NUM[s]!=-1 and NUM[s]!=c):
			ch = False
		NUM[s]=c
	if(NUM[0]==0 and N!=1):
		ch=False
	if(ch==False):
		print(-1)
	else:
		ans = 0
		t = 10**(N-1)
		for i in range(N):
			if(NUM[i]==-1 and i==0):
				if(N!=1):
					ans += t
			elif(NUM[i]!=-1):
				ans += (t * NUM[i])
			t //= 10

		print(ans)




if __name__ == '__main__':
	main()
Buggy code:
n, m = map(int, input().split())
ans = ['0'] * n
for i in range(m):
    s, c = map(int,input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        break
    if ans[s-1] != '0' and c != ans[s-1]:
        print(-1)
        break
    ans[s-1] = c
else:
    if n == 1 and int(ans[0]) == 0:
        print(0)
        break
    elif ans[0] == '0':
        ans[0] = '1'
    ans = map(str, ans)
    print(''.join(ans))

Fixed code:
n, m = map(int, input().split())
ans = ['0'] * n
for i in range(m):
    s, c = map(int,input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        break
    if ans[s-1] != '0' and c != ans[s-1]:
        print(-1)
        break
    ans[s-1] = c
else:
    if n == 1 and int(ans[0]) == 0:
        print(0)
        exit()
    elif ans[0] == '0':
        ans[0] = '1'
    ans = map(str, ans)
    print(''.join(ans))
Buggy code:
def solve(n, m):
    ans = [-1]*n
    for _ in range(m):
        s, c = map(int, input().split())
        s = s-1
        if ans[s] == c:
            continue
        elif ans[s] == -1:
            ans[s] = c
        else:
            return -1

    if ans[0] == '0':
        if n == 1:
            return '0'
        else:
            ans[0] = '1'
    for i in range(1, n):
        if ans[i] == -1:
            ans[i] = '0'
    return ''.join(ans)

n, m = map(int, input().split())
print(solve(n, m))

Fixed code:
def solve(n, m):
    ans = [-1] * n
    for _ in range(m):
        s, c = input().split()
        s = int(s) - 1
        if ans[s] == c:
            continue
        elif ans[s] == -1:
            ans[s] = c
        else:
            return -1
 
    if ans[0] == '0':
        if n == 1:
            return '0'
        else:
            return -1
    elif ans[0] == -1:
        if n == 1:
            return '0'
        else:
            ans[0] = '1'
    for i in range(1, n):
        if ans[i] == -1:
            ans[i] = '0'
    return ''.join(ans)
 
 
n, m = list(map(int, input().split()))
print(solve(n, m))
Buggy code:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = [-1] * N

for i in range(M):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] is -1:
        ans[s] = c
    elif not ans[s] == c:
        print(-1)
        exit(-1)
if ans[-1] == 0:
    print(-1)
    exit(-1)

a = 0
for i in range(N):
    if ans[i] is -1:
        ans[i] = 0
    a += ans[i]*10**(N-i-1)

print(a)


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

ans = [-1] * N

for i in range(M):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] is -1:
        ans[s] = c
    elif not ans[s] == c:
        print(-1)
        exit()

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

a = 0
for i in range(N):
    if ans[i] is -1:
        if i == 0 and N!= 1:
            ans[i] = 1
        else:
            ans[i] = 0
    a += ans[i]*10**(N-i-1)

print(a)
Buggy code:
n,m = map(int,input().split())

rest = []
for i in range(m):
    a,b = input().split()
    rest.apend((int(a),b))

done = False

for i in range(0,1000):
    x = str(i)
    if (len(x) == n):
        ok = True
        for t in rest:
            if (x[t[0] - 1] != t[1]):
                ok = False
                break
        if ok:
            print(i)
            done = True

if not done:
    print(-1)

Fixed code:
n,m = map(int,input().split())

rest = []
for i in range(m):
    a,b = input().split()
    rest.append((int(a),b))

done = False

for i in range(0,1000):
    x = str(i)
    if (len(x) == n):
        ok = True
        for t in rest:
            if (x[t[0] - 1] != t[1]):
                ok = False
                break
        if ok:
            print(i)
            done = True
            break

if not done:
    print(-1)