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

if num[0] == 0:
    num[0] = "1"
if ans==-1:
    print(ans)
else:
    print(int("".join(num)))


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

if num[0] == "-1":
    if n>1:
        num[0] = "1"
    else:
        num[0] = "0"

for i in range(n):
    if num[i]=="-1":
        num[i]="0"

if ans==-1:
    print(ans)
else:
    print(int("".join(num)))
Buggy code:
n,m=map(int,input().split())
num=0
array=[99999 for i in range(n)]
for _ in range(m):
  s,c = map(int,input().split())
  if array[s-1]==99999 or array[s-1]==c:
    array[s-1]=c
  else:
    array=[-1 for i in range(n)]
    break

if not n==1:
  for i in range(n):
    if not i==1:
      if array[i]==99999:
        array[i]=0
    else:
      array[i]=1
  if array[0]==0 or array[0]==-1:
    num=-1
  else:
    num=int(''.join(list(map(str,array))))
else:
  if array[0]==99999:
    num=-1
  else:
    num=array[0]
print(num)
    
    


Fixed code:
n,m=map(int,input().split())
num=0
array=[99999 for i in range(n)]
for _ in range(m):
  s,c = map(int,input().split())
  if array[s-1]==99999 or array[s-1]==c:
    array[s-1]=c
  else:
    array=[-1 for i in range(n)]
    break

if not n==1:
  for i in range(n):
    if not i==0:
      if array[i]==99999:
        array[i]=0
    else:
      if array[i]==99999:
        array[i]=1
  if array[0]==-1 or array[0]==0:
    num=-1
  else:
    num=int(''.join(list(map(str,array))))
else:
  if array[0]==99999:
    num=0
  else:
    num=array[0]
print(num)
Buggy code:
# -*- coding: utf-8 -*-
import sys
import random

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

# while True:
#     N = int(random.randint(1,3))
#     M = int()
    
ms = -1
upt = [False]*N
ans = [0]*N
for s,c in sc:
    ms = max(N-s,ms)
    if upt[s-1]:
        if ans[s-1] != c:
            print(-1)
            sys.exit()
        else:
            continue        
    else:
        upt[s-1] = True
        ans[s-1] = c

if upt[0]:
    if ans[0] == 0:
        if N>1:
            print(-1)
            sys.exit()
        else:
            print(0)
            sys.exit()

A = 0
base = 1
for i,a in enumerate(reversed(ans)):
    if i==N-1:
        A += 1*base
        base *= 10
    else:
        A += a * base
        base *= 10
print(A)
    


Fixed code:
# -*- coding: utf-8 -*-
import sys
import random

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

# while True:
#     N = int(random.randint(1,3))
#     M = int()
    
ms = -1
upt = [False]*N
ans = [0]*N
for s,c in sc:
    ms = max(N-s,ms)
    if upt[s-1]:
        if ans[s-1] != c:
            print(-1)
            sys.exit()
        else:
            continue        
    else:
        upt[s-1] = True
        ans[s-1] = c

if upt[0]:
    if ans[0] == 0:
        if N>1:
            print(-1)
            sys.exit()
        else:
            print(0)
            sys.exit()


if M==0 and N==1:
    print(0)
    sys.exit()

A = 0
base = 1
for i,a in enumerate(reversed(ans)):
    if i==N-1 and a == 0:
        A += 1*base
        base *= 10
    else:
        A += a * base
        base *= 10
print(A)
Buggy code:
N, M = list(map(int, input().split()))
sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))
    
for i in range(1000):
    if len(str(i)) == N:
        for j in range(M):
            s = sc[j][0]
            c = sc[j][1]
            if str(i)[s-1] != str(c):
                break
        else:
            print(i)
            break
        
            
                

Fixed code:
N, M = list(map(int, input().split()))
sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))
    
for i in range(1000):
    if len(str(i)) == N:
        for j in range(M):
            s = sc[j][0]
            c = sc[j][1]
            if str(i)[s-1] != str(c):
                break
        else:
            print(i)
            break
    
else:
    print(-1)
Buggy code:
n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    return -1
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==len(m):
      return i
    
  return -1

print(func(n, s_li_, c_li_))

Fixed code:
n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    if n==1:
      return 0
    else:
      return 10**(n-1)
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==m:
      return i
    
  return -1

print(func(n, m, s_li_, c_li_))
Buggy code:
import sys

# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    print(solve())


def solve():
    N, M = map(int, input().split())

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

    minimum = 10 ** (N-1)
    if minimum == 1:
        minimum = 0
    maximum = 10 ** N - 1

    ans = -1
    for i in range(minimum, maximum+1):
        candidate = str(i)
        ok = True
        for s, c in scs:
            if candidate[s-1] != c:
                ok = False
                break
        if ok:
            ans = int(candidate)
            break

    return ans


if __name__ == '__main__':
    main()


Fixed code:
import sys

# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    print(solve())


def solve():
    N, M = map(int, input().split())

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

    minimum = 10 ** (N-1)
    if minimum == 1:
        minimum = 0
    maximum = 10 ** N - 1

    ans = -1
    for i in range(minimum, maximum+1):
        candidate = str(i)
        ok = True
        for s, c in scs:
            if candidate[s-1] != str(c):
                ok = False
                break
        if ok:
            ans = int(candidate)
            break

    return ans


if __name__ == '__main__':
    main()
Buggy code:
nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
slist = []
clist = []
for i in range(m):
  sc = [int(i) for i in input().split()]
  slist.append(sc[0])
  clist.append(sc[1])

fl = 0
if (n == 1):
  if (slist[0] == 1 and clist[0] == 0):
    print('-1')
    fl = 1

answerlist = ['-1' for i in range(n)]
for (i,s), c in zip(enumerate(slist),clist):
  if (c == 0 and s == 1):
    print('-1')
    break
    fl = 1
  if (answerlist[s-1] != '-1' and answerlist[s-1] != str(c)):
    print('-1')
    break
    fl = 1
  answerlist[s-1] = str(c)
for i in range(n):
  if (answerlist[i]) == '-1':
    if (i == 0):
      answerlist[i] = '1'
    else:
      answerlist[i] = '0'
if fl == 1:
	print("".join(answerlist))

Fixed code:
nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
slist = []
clist = []

for i in range(m):
  sc = [int(i) for i in input().split()]
  slist.append(sc[0])
  clist.append(sc[1])

fl = 0
if (n == 1):
  if m != 0:
    if (slist[0] == 1 and clist[0] == 0):
      print('0')
      fl = 1
      exit()

answerlist = ['-1' for i in range(n)]
for (i,s), c in zip(enumerate(slist),clist):
  if (c == 0 and s == 1):
    print('-1')
    fl = 1
    exit()
  if (answerlist[s-1] != '-1' and answerlist[s-1] != str(c)):
    print('-1')
    fl = 1
    exit()
  answerlist[s-1] = str(c)
for i in range(n):
  if (answerlist[i]) == '-1':
    if (i == 0):
      if (n == 1):
        answerlist[i] = '0'
      else:
        answerlist[i] = '1'
    else:
      answerlist[i] = '0'
if fl == 0:
	print("".join(answerlist))
Buggy code:
n, m =map(int,input().split())
a = [-1] * n
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        flg = False
        break
if a[0] == -1:
    flg = False

if flg:
    num = 0
    for i in range(len(a)):
        if a[i] != -1:
            num += a[i] * (10**(m-i-1))
    print(num)
else:
    print(-1)

Fixed code:
n, m =map(int,input().split())
a = [-1] * n
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        flg = False
        break
        
if n >= 2:
    if a[0] == 0:
        flg = False
    elif a[0] == -1:
        a[0] = 1
else:
    if a[0] == -1:
        a[0] = 0
    
if flg:
    num = 0
    for i in range(len(a)):
        if a[i] != -1:
            num += a[i] * (10**(n-i-1))
    print(num)
else:
    print(-1)
Buggy code:
N, M = list(map(int, input().split()))
sc = []
for i in range(M):
  s, c = list(map(int, input().split()))
  sc.append([s, c])
print(sc)
for i in range(10**N):
  stri = str(i)
  if len(stri) == N:
    for j in range(M):
      k = sc[j][0]
      if not stri[k-1] == str(sc[j][1]):
        break
    else:
      print(i)
      break
else:
  print(-1)


Fixed code:
N, M = list(map(int, input().split()))
sc = []
for i in range(M):
  s, c = list(map(int, input().split()))
  sc.append([s, c])
for i in range(10**N):
  stri = str(i)
  if len(stri) == N:
    for j in range(M):
      k = sc[j][0]
      if not stri[k-1] == str(sc[j][1]):
        break
    else:
      print(i)
      break
else:
  print(-1)
Buggy code:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
for i in range(0, 10**N):
    if len(str(i))==N and all(str(i)[s-1] == c for s,c in sc)
    print(i)
else:
    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(0, 10**N):
    if len(str(i))==N and all(str(i)[s-1] == str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)
Buggy code:
#input
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())

#output
from collections import Counter
dp = [-1] * N
for i in range(M):
    if dp[s[i]-1] == -1:
        dp[s[i]-1] = c[i]
    elif c[i] != dp[s[i]-1]:
        print(-1)
        exit()

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

Fixed code:
#input
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())

#output
from collections import Counter
dp = [-1] * N
for i in range(M):
    if dp[s[i]-1] == -1:
        dp[s[i]-1] = c[i]
    elif c[i] != dp[s[i]-1]:
        print(-1)
        exit()

if N == 1:
    if dp[0] == -1:
        print(0)
    else:
        print(dp[0])
else:
    if dp[0] == 0:
        print(-1)
    else:
        for i in range(N):
            if dp[i] == -1:
                if i == 0:
                    print(1, end = "")
                else:
                    print(0, end = "")
            else:
                print(dp[i], end = "")
Buggy code:
N, M = map(int, input().split(' '))
if M == 0:
    if N == 1:
        print(0)
    else:
        print('1', '0' * (N - 1), sep='')
else:
    rst = [''] * N
    is_end = False
    for i in range(M):
        s, c = input().split(' ')
        idx = int(s) - 1
        if idx == 0 and N != 1 and c == '1':
            print(-1)
            is_end = True
            break
        elif rst[idx] == '':
            rst[idx] = c
        elif rst[idx] != c:
            print(-1)
            is_end = True
            break
    if not is_end:
        for i, j in enumerate(rst):
            if i == 0 and rst[i] == '':
                print('1', end='')
            elif rst[i] == '':
                print('0', end='')
            else:
                print(j, end='')

Fixed code:
N, M = map(int, input().split(' '))
rst = [''] * N
is_end = False
if M == 0:
    if N == 1:
        print(0)
    else:
        print('1', '0' * (N - 1), sep='')
else:
    for i in range(M):
        s, c = input().split(' ')
        if (int(s) - 1) == 0 and N != 1 and c == '0':
            print(-1)
            is_end = True
            break
        elif rst[int(s) - 1] == '':
            rst[int(s) - 1] = c
        elif rst[int(s) - 1] != c:
            print(-1)
            is_end = True
            break
    if not is_end:
        for i, j in enumerate(rst):
            if i == 0 and j == '':
                print(1, end='')
            else:
                if j == '':
                    print(0, end='')
                print(j, end='')
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())

ran = []
for i in range(10 ** (N - 1), 10 ** N):
    ran.append(i)
if N == 1:
    ran.append(0)

minimum = 10 ** N
for r in ran:
    st = str(r)
    ok = True
    for j in range(M):
        if st[s[j] - 1] != str(c[j]):
            ok = False
    if ok == True:
        minimum = min(minimum, r)
        break
if min == 10 ** N:
    print(-1)
else:
    print(minimum)


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())

ran = []
for i in range(10 ** (N - 1), 10 ** N):
    ran.append(i)
if N == 1:
    ran.append(0)

ran.sort()
minimum = 10 ** N
for r in ran:
    st = str(r)
    ok = True
    for j in range(M):
        if st[s[j] - 1] != str(c[j]):
            ok = False
    if ok == True:
        minimum = min(minimum, r)
        break
if minimum == 10 ** N:
    print(-1)
else:
    print(minimum)
Buggy code:
n,m = map(int,input().split())
num = [-1]*n
for i in range(m):
  s,c = map(int,input().split())
  if n!=1 and s==1 and c==0:
    print(-1)
    exit()
  if num[s-1]==-1: num[s-1] = c
  elif num[s-1]!=c:
    print(-1)
    eixt()
for i in range(n):
  if num[i] = -1: num[i] = 0
if num[0] = 0 and len(num)!=1: num[0] = 1
print(int(''.join(num)))


Fixed code:
n,m = map(int,input().split())
num = [-1]*n
for i in range(m):
  s,c = map(int,input().split())
  if n!=1 and s==1 and c==0:
    print(-1)
    exit()
  if num[s-1]==-1: num[s-1] = c
  elif num[s-1]!=c:
    print(-1)
    exit()
for i in range(n):
  if num[i] == -1: num[i] = 0
if num[0] == 0 and len(num)!=1: num[0] = 1
for i in range(n):
  print(num[i],end='')
Buggy code:
N, M = map(int, input().split())
A = [str(i) for i in range(1 * 10 ** (N - 1), 1 * 10 ** N)]
if N == 1:
  A.append('0')
for i in range(M):
  t = list(map(int, input().split()))
  A = [A[j] for j in range(len(A)) if int(A[j][t[0] - 1]) == t[1]]
print(-1 if not A == True else min(A))

Fixed code:
N, M = map(int, input().split())
A = [str(i) for i in range(1 * 10 ** (N - 1), 1 * 10 ** N)]
if N == 1:
  A.append('0')
for i in range(M):
  t = list(map(int, input().split()))
  A = [A[j] for j in range(len(A)) if int(A[j][t[0] - 1]) == t[1]]
print(-1 if (not A) == True else min(A))
Buggy code:
n,m=map(int,input().split())
p=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    if p[s-1]==-1:
        p[s-1]=c
    else:
        if c!=p[s-1]:
            print(-1)
            break
else:
    if p[0]==0 or p[0]!=-1:
        print(-1)
    else:
        s=""
        for i in range(n):
            if p[i]==-1:
                s+="0"
            else:
                s+=str(p[i])
        print(s)

Fixed code:
n,m=map(int,input().split())
p=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    if p[s-1]==-1:
        p[s-1]=c
    else:
        if c!=p[s-1]:
            print(-1)
            break
else:
    if n==1 and (p[0]==0 or p[0]==-1):
        print(0)
    elif p[0]==0:
        print(-1)
    else:
        s=""
        for i in range(n):
            if p[i]==-1:
                if i==0:
                    s+="1"
                else:
                    s+="0"
            else:
                s+=str(p[i])
        print(s)
Buggy code:
n,m = map(int,input().split())
ans = []

for i in range(m):
    s,c = map(int,input().split())
    li.append([s,c])

for i in range(10**(n-1),10**n):
    buf = str(i)
    flag = True
    for j in range(len(li)):
        if buf[li[j][0]-1] != str(li[j][1]):
            flag = False
    if flag:
        ans.append(buf)
        flag = True

ans.sort()
if ans:
    print(ans[0])
else:
    print(-1)


Fixed code:
n,m = map(int,input().split())
ans = []
li = []

for i in range(m):
    s,c = map(int,input().split())
    li.append([s,c])

if n == 1:
    for i in range(10):
        buf = str(i)
        flag = True
        for j in range(len(li)):
            if buf[li[j][0]-1] != str(li[j][1]):
                flag = False
        if flag:
            ans.append(buf)
            flag = True
else:
    for i in range(10**(n-1),10**n):
        buf = str(i)
        flag = True
        for j in range(len(li)):
            if buf[li[j][0]-1] != str(li[j][1]):
                flag = False
        if flag:
            ans.append(buf)
            flag = True

ans.sort()
if ans:
    print(ans[0])
else:
    print(-1)
Buggy code:
import sys
n,m = map(int,input().split())
num = ['t'] * n
for i in range(m):
  j,x = map(int,input().split())
  if num[j-1] == 't':
    num[j-1] = x
  elif num[j-1] != x:
    print(-1)
    sys.exit()

for i in range(n):
  if i == 0 and num[i] == 't':
    num[0] = '1'
  elif num[i] == 't':
    num[i] = '0'
  else:
    num[i] = str(num[i])
    
print(''.join(num))   
    

Fixed code:
import sys
n,m = map(int,input().split())
num = ['t'] * n

for i in range(m):
  j,x = map(int,input().split())
  if (j,x) == (1,0) and n != 1:
    print(-1)
    sys.exit()
  if num[j-1] == 't':
    num[j-1] = x
  elif num[j-1] != x:
    print(-1)
    sys.exit()
    
if (n,m) == (1,0):
  print(0)
  sys.exit()

for i in range(n):
  if i == 0 and num[i] == 't':
    num[0] = '1'
  elif num[i] == 't':
    num[i] = '0'
  else:
    num[i] = str(num[i])
    
print(''.join(num))
Buggy code:
n,m = map(int,input().split())
dig = [list(map(int,input().split())) for i in range(m)]

res = -1
for i in range(1000):
    s = str(i)
    ju = True
    for j in dig:
        if j[0] > len(s):
            ju = False
            break
        else:
            if int(s[j[0]-1]) == j[1]:
                continue
            else:
                ju = False
                break
    if ju:
        res = i
        break
print(res)

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

res = -1
st = 0 if n == 1 else 10**(n-1)
for i in range(st,1000):
    s = str(i)
    ju = True
    for j in dig:
        if j[0] > len(s):
            ju = False
            break
        else:
            if int(s[j[0]-1]) == j[1]:
                continue
            else:
                ju = False
                break
    if ju:
        res = i
        break
print(res)
Buggy code:
import sys
import math
sys.setrecursionlimit(int(1e6))

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())

digits = [-1]*N
fault = False
for i in range(M):
    d = s[i]-1
    if digits[d] >= 0:
        fault = True
        break
    digits[d] = c[i]

if fault:
    print(-1)
    exit()

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

ans = 0
for i in range(N):
    b = 10 ** (N - i - 1)
    n = digits[i] if digits[i] >= 0 else 0
    ans = ans + n * b

print(ans)


Fixed code:
import sys
import math
sys.setrecursionlimit(int(1e6))

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())

digits = [-1]*N
fault = False
for i in range(M):
    d = s[i]-1
    if digits[d] >= 0 and (digits[d] != c[i]):
        fault = True
        break
    digits[d] = c[i]

if fault:
    print(-1)
    sys.exit()

if (N>1) and (digits[0] == 0):
    print(-1)
    sys.exit()

ans = 0
for i in range(N):
    b = 10 ** (N - i - 1)
    n = digits[i] if digits[i] >= 0 else 0
    ans = ans + n * b

min_ans = 10 ** (N - 1) if N > 1 else 0
if ans < min_ans:
    ans = ans + min_ans

print(ans)
Buggy code:
N,M=map(int,input().split())
S=[]
C=[]
for i in range(M):
  s,c=map(int,input().split())
  S+=[s]
  C+=[c]
tf=1
ans=[]
for i in range(N):
  ans+=[-1]
for i in range(M):
  if ans[S[i]-1] ==-1:
    ans[S[i]-1]=C[i]
  else:
    if ans[S[i]-1]!=C[i]:
      tf=0
      break
    else:
      continue
for i in range(M):
  if ans[i]==-1:
    if i!=0:
      ans[i]=0
    else:
      ans[i]=1
if ans[0]==0:
  print('-1')
else:
  ansnum=''
  for i in range(M):
    ansnum+=str(ans[i])
  print(ansnum)

Fixed code:
N,M=map(int,input().split())
S=[]
C=[]
for i in range(M):
  s,c=map(int,input().split())
  S+=[s]
  C+=[c]
tf=1
ans=[]
for i in range(N):
  ans+=[-1]
for i in range(M):
  if ans[S[i]-1] ==-1:
    ans[S[i]-1]=C[i]
  else:
    if ans[S[i]-1]!=C[i]:
      tf=0
      break
    else:
      continue
for i in range(N):
  if ans[i]==-1:
    if i!=0 or (i==0 and N==1):
      ans[i]=0
    else:
      ans[i]=1
  elif ans[i]==0 and i==0 and N!=1:
    tf=0
    break
if tf==0:
  print('-1')
else:
  ansnum=''
  for i in range(N):
    ansnum+=str(ans[i])
  print(ansnum)
Buggy code:
N, M = map(int, input().split())
s = []
c = []
for m in range(M):
    si, ci = map(int, input().split())
    s.append(si)
    c.append(ci)

s = 10 ** (N - 1)
if N == 1:
    s -= 1

for i in range(s, 10 ** N):
    for m in range(M):
        if str(i)[s[m] - 1] != str(c[m]):
            break
    else:
        print(i)
        exit()

print(-1)


Fixed code:
N, M = map(int, input().split())
s = []
c = []
for m in range(M):
    si, ci = map(int, input().split())
    s.append(si)
    c.append(ci)

ss = 10 ** (N - 1)
if N == 1:
    ss -= 1

for i in range(ss, 10 ** N):
    for m in range(M):
        if str(i)[s[m] - 1] != str(c[m]):
            break
    else:
        print(i)
        exit()

print(-1)
Buggy code:
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ans = [-1] * N
    ok = True
    for i in range(M):
        s, c = map(int, input().split())
        if ans[s-1] != -1 or (N!=1 and c==0):
            ok = False
        ans[s-1] = c
    if ans[0] == -1:
        ans[0] = 1
    for i in range(1, N):
        if ans[i] == -1:
            ans[i] = 0
    
    if ok:
        print("".join(map(str, ans)))
    else:
        print(-1)



if __name__ == "__main__":
    main()

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

def main():
    N, M = map(int, input().split())
    if N == 1 and M == 0:
        print(0)
        return
    ans = [-1] * N
    ok = True
    for i in range(M):
        s, c = map(int, input().split())
        if (ans[s-1] != -1 and ans[s-1] != c) or (N!=1 and s==1 and c==0):
            ok = False
        ans[s-1] = c
    if ans[0] == -1:
        ans[0] = 1
    for i in range(1, N):
        if ans[i] == -1:
            ans[i] = 0
    
    if ok:
        print("".join(map(str, ans)))
    else:
        print(-1)



if __name__ == "__main__":
    main()