qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(tuple(map(int, input().split())))


for i in range(10**(n-1), 10**n):
    s = str(i)
    flag = True
    if len(s) == n and all([s[sc[j][0]-1] == str(sc[j][1])] for j in range(m)):
        print(s)
        exit(0)


print('-1')


#
# for i in range(1, n+1):
#    if list(zip(*sc))[0].count(i) > 1:
#        print('-1')
#        exit(0)
#
#
# if min(list(zip(*sc))[0]) != 1:
#    print('-1')
#    exit(0)
#
# for i in sc:
#    if i[0] == 1 and i[1] == 0 and n > 1:
#        print('-1')
#        exit(0)
#
#ans = [0, 0, 0]
# for i in sc:
#    ind, val = i[0]-1, i[1]
#    if ans[ind] != 0:
#        ans[ind] = min(ans[ind], val)
#    else:
#        ans[ind] = val
#
#print(''.join(list(map(str, ans))))


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


for i in range(10**n):
    s = str(i)
    if len(s) == n and all([s[sc[j][0]-1] == str(sc[j][1]) for j in range(m)]):
        print(s)
        exit(0)


print('-1')


#
# for i in range(1, n+1):
#    if list(zip(*sc))[0].count(i) > 1:
#        print('-1')
#        exit(0)
#
#
# if min(list(zip(*sc))[0]) != 1:
#    print('-1')
#    exit(0)
#
# for i in sc:
#    if i[0] == 1 and i[1] == 0 and n > 1:
#        print('-1')
#        exit(0)
#
#ans = [0, 0, 0]
# for i in sc:
#    ind, val = i[0]-1, i[1]
#    if ans[ind] != 0:
#        ans[ind] = min(ans[ind], val)
#    else:
#        ans[ind] = val
#
#print(''.join(list(map(str, ans))))
Buggy code:
n, m = map(int, input().split())
s = []
c = []
ans = [0 for _ in range(n)]
has_num = [False for _ in range(n)]

for i in range(m):
    S, C = map(int, input().split())
    s.append(S)
    c.append(C)

    if has_num[S - 1] == True and ans[S-1] != C:
        print(-1)
        exit(0)
    has_num[S-1] = True

    ans[S - 1] = C

# if ans[0] == 0 and n == 1 and m != 0:
#     print(-1)
#     exit(0)

if ans[0] == 0 and n != 1:
    ans[0] = 1

maped_ans = map(str, ans)
print(''.join(maped_ans))

Fixed code:
n, m = map(int, input().split())
s = []
c = []
ans = [0 for _ in range(n)]
has_num = [False for _ in range(n)]

for i in range(m):
    S, C = map(int, input().split())
    s.append(S)
    c.append(C)

    if has_num[S - 1] == True and ans[S-1] != C:
        print(-1)
        exit(0)
    has_num[S-1] = True

    ans[S - 1] = C

if ans[0] == 0 and has_num[0] == True and n != 1:
    print(-1)
    exit(0)

if ans[0] == 0 and n != 1:
    ans[0] = 1

maped_ans = map(str, ans)
print(''.join(maped_ans))
Buggy code:
n, m = map(int, input().split())
  
answer = [-1]*n

for i in range(m):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    if n == 1:
      print(0)
      exit()
    else:
      print(-1)
  if answer[s-1] == -1 or answer[s-1] == c:
    answer[s-1] = c
  else:
    print(-1)
    exit()

if answer[0] == -1:
  answer[0] = 1
for j in range(n):
  if answer[j] == -1:
    answer[j] = 0
    
answer = [str(x) for x in answer] 

print(int(''.join(answer)))



Fixed code:
n, m = map(int, input().split())
if n == 1 and m == 0:
  print(0)
  exit()
  
answer = [-1]*n

for i in range(m):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    if n == 1:
      print(0)
      exit()
    else:
      print(-1)
      exit()
  if answer[s-1] == -1 or answer[s-1] == c:
    answer[s-1] = c
  else:
    print(-1)
    exit()

if answer[0] == -1:
  answer[0] = 1
for j in range(n):
  if answer[j] == -1:
    answer[j] = 0
    
answer = [str(x) for x in answer] 

print(int(''.join(answer)))
Buggy code:
f = True
n,m=map(int,input().split())
number = [-1 for i in range(n)]
for i in range(m):
  s,c=list(map(int,input().split()))
  s -= 1
  if s == 0 and c == 0 and n > 1:
    f = False
  elif number[s] == -1:
    number[s] = c
    f = False
  else:
    f = False
if not f:
  print(-1)
elif n == 1:
  if number[0] == -1:
    print(0)
  else:
    print(number[0])
else:
  if number[0] == -1:
    number[0] = 1
  for i in range(1,n):
    if number[i] == -1:
      number[i] = 0
  print(''.join(map(str,number)))

Fixed code:
f = True
n,m=map(int,input().split())
number = [-1 for i in range(n)]
for i in range(m):
  s,c=list(map(int,input().split()))
  s -= 1
  if s == 0 and c == 0 and n > 1:
    f = False
  elif number[s] == -1 or number[s] == c:
    number[s] = c
  else:
    f = False
if not f:
  print(-1)
elif n == 1:
  if number[0] == -1:
    print(0)
  else:
    print(number[0])
else:
  if number[0] == -1:
    number[0] = 1
  for i in range(1,n):
    if number[i] == -1:
      number[i] = 0
  print(''.join(map(str,number)))
Buggy code:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=-1
for i in range(10**3):
    if (len(str(i))==n):
        flag=1
        for s,c in sc:
            if str(i)[s-1] != str(c):
                flag=0
            if flag==1:
                ans =i
                break
print(ans)

Fixed code:
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=-1
for i in range(10**3):
    if (len(str(i))==n):
        flag=1
        for s,c in sc:
            if str(i)[s-1] != str(c):
                flag=0
        if flag==1:
            ans =i
            break
print(ans)
Buggy code:
N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
    

n = int('9'*N)
ans = []

for i in range(n+1):
    if len(str(i)) == 1:
        I = '00'+str(i)
    elif len(str(i)) == 2:
        I = '0'+str(i)
    else:
        I = str(i)
    for m in range(M):
        if N >= 2 and S[m] == 1 and C[m] == 0:
            break
        if I[S[m]-1] != str(C[m]):
            break
    else:
        ans.append(I)

if len(ans) == 0:
    print(-1)
    exit()

ans_map = list(map(int,ans))

print(ans_map)

print(min(ans_map))


Fixed code:
N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
    

n = int('9'*N)
if N > 1:
    start = int('1' + '0'*(N-1))
else:
    start = 0
ans = []

for i in range(start, n+1):
    I = str(i)
    for m in range(M):
        if N >= 2 and S[m] == 1 and C[m] == 0:
            break
        if S[m] <= len(I):
            if I[S[m]-1] != str(C[m]):
                break
    else:
        ans.append(I)

if len(ans) == 0:
    print(-1)
    exit()

ans_map = list(map(int,ans))

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

ans = [-1 for i in range(N)]
flag = False
for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] == c:
        continue
    else:
        flag = True
        break

if len(ans) > 1 and ans[0]:
    ans[0] = 1

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

if len(ans) > 1 and ans[0] == 0:
    flag = True

if flag:
    print(-1)
else:
    print("".join([str(c) for c in ans]))


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

ans = [-1 for i in range(N)]
flag = False
for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] == c:
        continue
    else:
        flag = True
        break

if len(ans) > 1 and ans[0] == -1:
    ans[0] = 1

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

if len(ans) > 1 and ans[0] == 0:
    flag = True

if flag:
    print(-1)
else:
    print("".join([str(c) for c in ans]))
Buggy code:

result = None
N, M = [int(i) for i in input().split()]

a = [None for i in range(N)]

for i in range(M):
    s, c = [int(i) for i in input().split()]
    s = s - 1

    if a[s] is not None and c != a[s]:
        result = False
    a[s] = c

if a[0] is None:
    a[0] = 1

a.reverse()

if result is None:
    result = 0
    for i, num in enumerate(a):
        if num is None:
            num = 0
        result += num * 10**i

if result is False:
    result = -1


print(result)

Fixed code:

result = None
N, M = [int(i) for i in input().split()]

a = [None for i in range(N)]

for i in range(M):
    s, c = [int(i) for i in input().split()]
    s = s - 1

    if a[s] is not None and c != a[s]:
        result = False
    a[s] = c

if a[0] == 0 and N >=2:
    result = False

if a[0] is None and N >= 2:
    a[0] = 1

a.reverse()

if result is None:
    result = 0
    for i, num in enumerate(a):
        if num is None:
            num = 0
        result += num * 10**i

if result is False:
    result = -1


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


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

ans = [0]*n
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if ans[s] == 0 or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()
print(*ans, sep='')

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

ans = [0]*n
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if ans[s] == 0 or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()
if n > 1 and ans[0] == '0':
    print(-1)
    exit()
if n > 1 and ans[0] == 0:
    ans[0] = '1'
print(*ans, sep='')
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 i in range(1000):
    *t, = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break

    if ok:
        print(i)
        quit()

print(-1)


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

for i in range(1000):
    *t, = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break
    if ok:
        print(i)
        quit()

print(-1)
Buggy code:
n,m = map(int,input().split())
keta = []
number = []

for i in range(m):
    n,a=input().split()
    keta.append(int(n))
    number.append(a)

ccount = 0
count = 0   
ans = 0
if n == 3:
   ans = 100
if n == 2:
   ans = 10
if n == 1:
   ans = 0

while count == 0:
   ans = str(ans)
   for i in range(0,m):
      if ans[keta[i]-1] == number[i]:
         ccount += 1
   if ccount == m:
      count += 1
   ccount = 0
   ans = int(ans)
   ans += 1
   if n = 3 and (ans - 1) == 1000:
      ans = 0
      break
   if n = 2 and (ans - 1) == 100:
      ans = 0
      break
   if n = 1 and (ans - 1) == 10:
      ans = 0
      break
print(ans - 1)

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

for i in range(m):
    b,a=input().split()
    keta.append(int(b))
    number.append(a)

ccount = 0
count = 0   
ans = 0
if n == 3:
   ans = 100
else:
   pass
if n == 2:
   ans = 10
else:
   pass
if n == 1:
   ans = 0
else:
   pass

while count == 0:
   ans = str(ans)
   for i in range(0,m):
      if ans[keta[i]-1] == number[i]:
         ccount += 1
   if ccount == m:
      count += 1
   ccount = 0
   ans = int(ans)
   ans += 1
   if n == 3 and (ans - 1) == 1000:
      ans = 0
      break
   if n == 2 and (ans - 1) == 100:
      ans = 0
      break
   if n == 1 and (ans - 1) == 10:
      ans = 0
      break
print(ans - 1)
Buggy code:
N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))

def func(N,M,sc):
    ans = [0]*N
    for i in range(M):
        s = sc[i][0]-1
        c = sc[i][1]
        if c == 0:
            c = 'x'
        if ans[s] == 0 or ans[s] == c:
            ans[s] = c
        else:
            return -1
    for i in range(N):
        if ans[i] == 'x':
            ans[i] = 0
    if N != 1 and ans[0] == 0:
        ans[0] = 1
    if N != 1 and ans[0] == 0:
        return -1
    return int(''.join(map(str,ans)))

print(func(N,M,sc))

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

def func(N,M,sc):
    ans = [0]*N
    for i in range(M):
        s = sc[i][0]-1
        c = sc[i][1]
        if c == 0:
            c = 'x'
        if ans[s] == 0 or ans[s] == c:
            ans[s] = c
        else:
            return -1
    if N != 1 and ans[0] == 0:
        ans[0] = 1
    for i in range(N):
        if ans[i] == 'x':
            ans[i] = 0
    if N != 1 and ans[0] == 0:
        return -1
    return int(''.join(map(str,ans)))

print(func(N,M,sc))
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 i in range(10**(N-1), 10**(N)):
    t = str(i)
    flag = True
    for j in range(M):
        if t[S[j]-1] != str(C[j]):
            flag = False
    if flag:
        print(i)
        F = True
        break
if not F:
    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)
F = False
for i in range(10**(N)):
    t = str(i)
    flag = True
    if len(t) != N:
        continue
    for j in range(M):
        if t[S[j]-1] != str(C[j]):
            flag = False
    if flag:
        print(i)
        F = True
        break
if not F:
    print(-1)
Buggy code:
N, M = [int(i) for i in input().split()]
s = [0] * M
c = [0] * M
for i in range(N):
  s[i], c[i] = map(int, input().split())

ans = 1000
for i in range(1000):
  S = str(i)
  if len(S) != N:
    continue
  
  is_ok = True
  for j in range(N):
    if S[s[j]] != c[j]:
      is_ok = False
      
  if is_ok:
    ans = min(ans, i)

if ans == 1000:
  print(-1)
else:
  print(ans)


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

ans = 1000
for i in range(1000):
  S = str(i)
  if len(S) != N:
    continue
  
  is_ok = True
  for j in range(M):
    if S[s[j]-1] != str(c[j]):
      is_ok = False
      
  if is_ok:
    ans = min(ans, i)

if ans == 1000:
  print(-1)
else:
  print(ans)
Buggy code:
def guess(N,M,S,C,guess_num):
    no_num=False
    if len(guess_num)!=1:
        guess_num[0]=1
    else:
        pass

    for m in range(M):
        if guess_num[S[m]-1]==0 or guess_num[S[m]-1]==C[m]:
            guess_num[S[m]-1]=C[m]
        else:
            no_num=True
            break
    
    if len(guess_num)!=1 and (no_num==True or guess_num[0]==0):
        return -1
    else:
        return int("".join(map(str,guess_num)))

def main():
    #initialize
    NM=[]
    SC=[]
    #input
    NM=list(map(int,input().strip().split()))
    N=NM[0]
    M=NM[1]
    for n in range(M):
        SC.append(list(map(int,input().strip().split())))
    S=[SC[i][0] for i in range(M)]
    C=[SC[j][1] for j in range(M)]

    guess_num=[0 for n in range(N)]
    
    print(guess(N,M,S,C,guess_num))

main()

Fixed code:
def guess(N,M,S,C,guess_num):
    no_num=False
    if len(guess_num)!=1:
        guess_num[0]=1
    else:
        pass

    num_input=[0 for n in range(N)]
    for m in range(M):
        if num_input[S[m]-1]==0 or guess_num[S[m]-1]==C[m]:
            guess_num[S[m]-1]=C[m]
            num_input[S[m]-1]=1
        else:
            no_num=True
            break
    
    if no_num==True or (len(guess_num)!=1 and guess_num[0]==0):
        return -1
    else:
        return int("".join(map(str,guess_num)))

def main():
    #initialize
    NM=[]
    SC=[]
    #input
    NM=list(map(int,input().strip().split()))
    N=NM[0]
    M=NM[1]
    for n in range(M):
        SC.append(list(map(int,input().strip().split())))
    S=[SC[i][0] for i in range(M)]
    C=[SC[j][1] for j in range(M)]

    guess_num=[0 for n in range(N)]
    
    print(guess(N,M,S,C,guess_num))

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

S, C = [], []
for i in range(M):
  s, c = map(int, input().split())
  S += [s-1]
  C += [str(c)]
  
if N == 1:
  for i in range(10):
    flag = 1
  for m in range(M):
      if i_str[S[m]] != C[m]:
        flag = 0
        break
    if flag:
      print(i)
      break
  else:
    print(-1) 
else:
  for i in range(10**(N-1), 10**N):
    flag = 1
    i_str = str(i)
    for m in range(M):
      if i_str[S[m]] != C[m]:
        flag = 0
        break
    if flag:
      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 += [s-1]
  C += [str(c)]
  
if N == 1:
  for i in range(10):
    flag = 1
    for m in range(M):
      if str(i) != C[m]:
        flag = 0
        break
    if flag:
      print(i)
      break
  else:
    print(-1) 
else:
  for i in range(10**(N-1), 10**N):
    flag = 1
    i_str = str(i)
    for m in range(M):
      if i_str[S[m]] != C[m]:
        flag = 0
        break
    if flag:
      print(i)
      break
  else:
    print(-1)
Buggy code:
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)

ans = [10 for i in range(N)]
x = ''

for j in range(M):
  if ans[s[j]-1] == 10:
     ans[s[j]-1] = c[j]
  elif ans[s[j]-1] != 10 and  ans[s[j]-1] != c[j]:
    print('-1')
    exit()
  
for k in range(N):
  if ans[k] == 10:
    ans[k] = 0
if N == 1:
  for l in range(N):
    x += str(ans[l])
  print(x)
  exit()
else:
  if ans[0] == 0 :
  print('-1')
  else :
  for l in range(N):
    x += str(ans[l])
  print(x)
   
  

Fixed code:
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)

ans = [10 for i in range(N)]
x = ''

for j in range(M):
  if ans[s[j]-1] == 10:
     ans[s[j]-1] = c[j]
  elif ans[s[j]-1] != 10 and  ans[s[j]-1] != c[j]:
    print('-1')
    exit()
  
for k in range(N):
  if k == 0 and ans[k] == 10 and N != 1:
    ans[k] = 1
  elif k == 0 and ans[k] == 10 and N == 1:
    ans[k] = 0
  elif ans[k] == 10:
     ans[k] = 0
if N == 1:
  print(ans[0])
  exit()
else:
  if ans[0] == 0 :
    print('-1')
  else :
    for l in range(N):
      x += str(ans[l])
    print(x)
Buggy code:
N,M=map(int, input().split())

sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))
for i in range(10**N):
    anc = str(i)
    if len(ans) == N and all(ans[s-1] == str(c) for s,c in sc):
        print(ans)
        quit()
print(-1)

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

sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))
for i in range(10**N):
    ans = str(i)
    if len(ans) == N and all(ans[s-1] == str(c) for s,c in sc):
        print(ans)
        quit()
print(-1)
Buggy code:
N,M=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(M)]

for x in range(0, 1000):
    nx=x//10
    d=[x%10]
    while(nx):
        d.append(nx%10)
        nx//=10
    d.reverse

    if len(d)!=N: continue

    chk=True
    for i in range(M):
        if(d[arr[i][0]-1]!=arr[i][1]): chk=False
    if chk: print(x);exit()

print(-1)

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

for x in range(0, 1000):
    nx=x//10
    d=[x%10]
    while(nx):
        d.append(nx%10)
        nx//=10

    d.reverse()

    if len(d)!=N: continue

    chk=True
    for i in range(M):
        if(d[arr[i][0]-1]!=arr[i][1]): chk=False
    if chk: print(x);exit()

print(-1)
Buggy code:
N, M = list(map(int, input().split()))

num = [-1]
for _ in range(N - 1):
	num += [-1]

for _ in range(M):
  s, c = list(map(int, input().split()))
  if num[s - 1] != -1 and num[s - 1] != c:
    print('-1')
    exit()
  num[s - 1] = c

if num[0] == -1:
  num[0] = 1

print(''.join(map(str, map(lambda x: 0 if x == -1 else x, num))))

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

num = [-1]
for _ in range(N - 1):
  num += [-1]

for _ in range(M):
  s, c = list(map(int, input().split()))
  if (s == 1 and c == 0 and N != 1) or (num[s - 1] != -1 and num[s - 1] != c):
    print('-1')
    exit()
  num[s - 1] = c

if num[0] == -1:
  if len(num) == 1:
    print('0')
    exit()
  num[0] = 1

print(''.join(map(str, map(lambda x: 0 if x == -1 else x, num))))
Buggy code:
import sys
import math
N, M = map(int, input().split())
NUMS = [list(map(int, input().split())) for _ in range(M)]


def solve():
    if M == 0:
        print("-1")
        return

    for n in range(10 ** (N - 1), 10 ** (N)):
        res = 0
        for s, c in NUMS:
            if str(n)[s - 1] == str(c):
                res += 1
        
        if res == M:
            print(n)
            return
            
    print("-1")

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


def solve():
    for n in range(10 ** (N - 1) if N > 1 else 0, 10 ** (N)):
        res = 0
        for s, c in NUMS:
            if str(n)[s - 1] == str(c):
                res += 1
        
        if res == M:
            print(n)
            return
            
    print("-1")
    
solve()
Buggy code:
n, m = [int(i) for i in input().split()]
sc = [list(map(int, input().split())) for _ in range(m)]


ans = -1
for i in range(10**(n-1), 10**n):
    for s, c in sc:
        if str(i)[s-1] != str(c):
            break
    else:
        ans = i
        break
if n == 1:
    if m == 0:
        ans = 0
    else:
        for s, c in sc:
            if s == 1 and c == 0:
                ans = 0
                break
print(sc)


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


ans = -1
for i in range(10**(n-1) if n > 1 else 0, 10**n):
    for s, c in sc:
        if str(i)[s-1] != str(c):
            break
    else:
        ans = i
        break
print(ans)
Buggy code:
n, m = map(int, input().split())

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

if n == 1:
    a = [str(i) for i in range(10)]
elif n == 2:
    a = [str(i) for i in range(10:100)]
elif n == 3:
    a = [str(i) for i in range(100:1000)]

ans = []

for i in a:
    b = True
    for j in s:
        if int(i[j[0]-1]) != j[1]:
            b = False
            break
    if b:
        ans.append(i)

if len(ans) == 0:
    print(-1)
else:
    print(min(ans))



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

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

if n == 1:
    a = [str(i) for i in range(10)]
elif n == 2:
    a = [str(i) for i in range(10,100)]
elif n == 3:
    a = [str(i) for i in range(100,1000)]

ans = []

for i in a:
    b = True
    for j in s:
        if int(i[j[0]-1]) != j[1]:
            b = False
            break
    if b:
        ans.append(i)

if len(ans) == 0:
    print(-1)
else:
    print(min(ans))