qyliang/CodeNanoFix huggingface dataset:
Buggy code:
ddimport sys
INF = float("inf")


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):

    for i in range(1000):
        A = str(i)
        if len(A) != N:
            continue
        flag = True
        for ss, cc in zip(s, c):
            if int(A[ss-1]) != cc:
                flag = False
                break

        if flag == True:
            print(A)
            return
    print(-1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)


if __name__ == '__main__':
    main()


Fixed code:
import sys
INF = float("inf")


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):

    for i in range(1000):
        A = str(i)
        if len(A) != N:
            continue
        flag = True
        for ss, cc in zip(s, c):
            if int(A[ss-1]) != cc:
                flag = False
                break

        if flag == True:
            print(A)
            return
    print(-1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)


if __name__ == '__main__':
    main()
Buggy code:
import sys
 
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
 
flagN = [False]*N
numN = [0]*N
numN[0] = 1
 
for sc in SC:
  s, c = sc[0]-1, sc[1]
  if flagN[s] and numN[s]==c or N>1 and s==c==0:
    print(-1)
    sys.exit()
  else:
    flagN[s] = True
    numN[s] = c

ans = ''
for n in numN:
  ans += str(n)
print(ans)

Fixed code:
import sys
 
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
 
flagN = [False]*N
numN = [0]*N
if N > 1:
  numN[0] = 1

for sc in SC:
  s, c = sc[0], sc[1]
  if flagN[s-1] == False:
    flagN[s-1] = True
    numN[s-1] = c
  elif numN[s-1] == c:
    continue
  else:
    print(-1)
    sys.exit()
    
if N != 1 and numN[0] == 0:
  print(-1)
  sys.exit()

ans = ''
for n in numN:
  ans += str(n)
print(ans)
Buggy code:
n, m = map(int, input().split())
s_li = [list(map(int, input().split())) for i in range(m)]

if n != 1:
    ans = ['1']
    ans.extend(['0'] * (n - 1))
else:
    ans = ['0']
    flag = [0] * n

for s, c in s_li:
    if flag[s - 1] == 0:
        ans[s - 1] = '{}'.format(c)
        flag[s - 1] = 1
    elif flag[s - 1] == 1 and int(ans[s - 1]) == c:
        continue
    else:
        ans = ['-1']
        break

ans = int(('').join(ans))

if n != 1 and (ans // 10**(n - 1)) == 0:
    ans = -1

print(ans)

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

if n != 1:
    ans = ['1']
    ans.extend(['0'] * (n - 1))
else:
    ans = ['0']
flag = [0] * n

for s, c in s_li:
    if flag[s - 1] == 0:
        ans[s - 1] = '{}'.format(c)
        flag[s - 1] = 1
    elif flag[s - 1] == 1 and int(ans[s - 1]) == c:
        continue
    else:
        ans = ['-1']
        break

ans = int(('').join(ans))

if n != 1 and (ans // 10**(n - 1)) == 0:
    ans = -1

print(ans)
Buggy code:
N, M = [int(i) for i in input().split()]
valid = True
ans = [-1]*N
for a in range(M):
    s,c = [int(i) for i in input().split()]
    if ans[s-1] == -1:
        ans[s-1] = c
    else:
        valid = False

for a in range(len(ans)):
    if ans[a] == -1:
        ans[a] = 0
if valid:
    n = "".join(map(str, ans))
    if len(n) != 0 and n[0] == "0":
        print(-1)
    else:
        print(int(n))
else:
    print(-1)

Fixed code:
N, M = [int(i) for i in input().split()]
valid = True
ans = [-1]*N
for a in range(M):
    s,c = [int(i) for i in input().split()]
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] != c:
        valid = False

for a in range(len(ans)):
    if ans[a] == -1:
        if a == 0:
            if len(ans) == 1:
                ans[a] = 0
            else:
                ans[a] = 1
        else:
            ans[a] = 0
if valid:
    n = "".join(map(str, ans))
    if len(n) != 1 and n[0] == "0":
        print(-1)
    else:
        print(int(n))
else:
    print(-1)
Buggy code:
n , m = map(int, input().split())

num = [-1] * n

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

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

print(''.join(map(str, num)))



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

num = [-1] * n

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

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

print(''.join(map(str, num)))
Buggy code:
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
N = [None] * n
for s, c in L:
    if N[s - 1] is None:
        N[s - 1] = c
    elif N[s - 1] == c:
        continue
    else:
        print(-1)
        exit()
for i in range(n):
    if N[i] is None:
        N[i] = 0
if N[0] == 0:
    print(-1)
else:
    print(*N, sep='')


Fixed code:
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(m)]
N = [None] * n
for s, c in L:
    if N[s - 1] is None:
        N[s - 1] = c
    elif N[s - 1] == c:
        continue
    else:
        print(-1)
        exit()

if n == 1:
    if N[0] is None:
        N[0] = 0
    print(*N)
    exit()
elif N[0] == 0:
    print(-1)
    exit()

for i in range(n):
    if i == 0 and N[0] is None:
        N[0] = 1
    elif N[i] is None:
        N[i] = 0
print(*N, sep='')
Buggy code:
n, m = list(map(int, input().split()))

    
out = ['a']*n
err_flg = False
err_flg2 = False 

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

    if s[0]==1 and s[1]==0 and n > 1:
        err_flag = True
    elif s[0]==1 and s[1]==0 and n==1:
        err_flg2 = True
    elif m==0 and n==1:
        err_flg2 = True

    if out[s[0]-1]=='a':
        out[s[0]-1] = s[1]
    elif out[s[0]-1]==s[1]:
        out[s[0]-1] = s[1]
    # elif out[s[0]-1]!=s[1]:
    elif out[s[0]-1]!=s[1]:
        err_flg = True


if out[0]=='a' and n>1:
    out[0]=1
    

out_s = "".join(map(str,out))


if err_flg:
    print('-1')
# elif m==0 and n==1:
#     print(0)
elif err_flg2:
    print('0')
else:
    print(out_s.replace('a','0'))

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

    
out = ['a']*n
err_flg = False
err_flg2 = False 

for i in range(m):
    s = list(map(int, input().split()))
    # print(s)

    if s[0]==1 and s[1]==0 and n==1:
        err_flg2 = True
    elif m==0 and n==1:
        err_flg2 = True
    elif s[0]==1 and s[1]==0 and n > 1:
        # print('kore')
        err_flg = True

    if out[s[0]-1]=='a':
        out[s[0]-1] = s[1]
    elif out[s[0]-1]==s[1]:
        out[s[0]-1] = s[1]
    # elif out[s[0]-1]!=s[1]:
    elif out[s[0]-1]!=s[1]:
        err_flg = True


if out[0]=='a' and n>1:
    out[0]=1
    

out_s = "".join(map(str,out))

if err_flg2:
    print('0')
    # print('err2')
elif err_flg:
    print('-1')
    # print('err')
else:
    print(out_s.replace('a','0'))
Buggy code:
N,M = map(int,input().split())
i = 0
l = [-1]*N
t = 0
while i<M:
    s,c = map(int,input().split())
    if l[s-1] == -1 or l[s-1] == c:
        l[s-1] = c  
    else:
        t = -1 
    i+=1

for i in range(0,N):
    if l[i]==-1:
        l[i]=0
    i+=1

if (l[0] == 0):
    l[0] = 1

if t == 0:
    for i in range(0,N):
        t += l[i]*(10**(N-i-1))
        i+=1

print(t)

Fixed code:
N,M = map(int,input().split())
i = 0
l = [-1]*N
t = 0
while i<M:
    s,c = map(int,input().split())
    if N>1 and s == 1 and c == 0:
        t = -1
    elif l[s-1] == -1 or l[s-1] == c:
        l[s-1] = c  
    else:
        t = -1 
    i+=1

if N>1 and l[0] == -1:
    l[0] = 1
elif l[0] == -1:
    l[0] = 0

for i in range(0,N):
    if l[i]==-1:
        l[i]=0
    i+=1

if t == 0:
    for i in range(0,N):
        t += l[i]*(10**(N-i-1))
        i+=1

print(t)
Buggy code:
#graph implementation
import math
n,m=map(int,input().split())
ans=['l']*n
flag=False
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]=='l':
      ans[s-1]=c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit(0)
    if s-1==0:
        flag=True
#print(ans)
if not flag:
    ans[0]=1
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()


Fixed code:
#graph implementation
import math
n,m=map(int,input().split())
ans=['l']*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]=='l':
      ans[s-1]=c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit(0)
if ans[0]=='l' and n>1:
    ans[0]=1
for i in range(n):
    if ans[i]=='l':
        ans[i]=0
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()
Buggy code:
N,M=map(int,input().split())
numbers=[' ',]*N
kotae=0
for a in range(M):
    suuji=[]
    s,c=input().split()
    if numbers[int(s)-1]==' ':
        numbers[int(s)-1]=c
    else:
        if numbers[int(s)-1]==c:
            continue
        else:
            print('-1')
            kotae+=1
            break

for a in range(3):
    if numbers[a]==' ':
        numbers[a]=0
if numbers[0]==0:
    del numbers[0]
    if numbers[0]==0:
        del numbers[0]
        if numbers[0]==0:
            del numbers[0]
if kotae==0:
    if len(numbers)!=N:
        print('-1')
    else:
       moji=''
       for a in numbers:
           moji+=str(a)
       print(moji)


Fixed code:
N,M=map(int,input().split())
numbers=[' ',]*N
kotae=0
for a in range(M):
    suuji=[]
    s,c=input().split()
    if numbers[int(s)-1]==' ':
        numbers[int(s)-1]=int(c)
    else:
        if numbers[int(s)-1]==int(c):
            continue
        else:
            print('-1')
            kotae+=1
            break
if numbers[0]==' ' and N==3:
    numbers[0]=1
if N==2 and numbers[0]==' ':
    numbers[0]=1
for a in range(N):
    if numbers[a]==' ':
        numbers[a]=0
if N==3:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
            if numbers[0] == 0:
                del numbers[0]
if N==2:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
if kotae==0:
    if len(numbers)!=N:
        print('-1')
    else:
       moji=''
       for a in numbers:
           moji+=str(a)
       print(int(moji))
Buggy code:
n, m = map(int, input().split())
lst = []
for _ in range(m):
    s, c = map(int, input().split())
    lst.append([s-1,c])

ans = []
for _ in range(10**(n)-1):
    i = 1
    nums = list(str(_))
    while len(nums) < n:
        nums.insert(0,[])
    for s in lst:
        if nums[s[0]] != s[1]:
            i = 0
            break
        if i:
            ans.append(_)
if ans:
    print(min(ans))
else:
    print(-1)

Fixed code:
n, m = map(int, input().split())
lst = []
for _ in range(m):
    s, c = map(int, input().split())
    lst.append([s-1,c])
    
ans = []
for _ in range(10**(n)):
    i = 1
    nums = list(str(_))
    while len(nums) < n:
        nums.insert(0,[])
    for s in lst:
        if nums[s[0]] != str(s[1]):  
            i = 0
            break
    if i == 1 and not [] in nums:
        ans.append(_)

if ans:
    print(min(ans))
else:
    print(-1)
Buggy code:
N, M = map(int, input().split())
S = []
C = []
for _ in range(N):
  s, c = map(int, input().split())
  S.append(s - 1)
  C.append(c)

num = ['*'] * N

for s, c in zip(S, C):
  if num[s] == '*':
    num[s] = str(c)
  elif num[s] != str(c):
    print(-1)
    exit()

print(''.join(num).replace('*', '0'))

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)

num = ['*'] * N

for s, c in zip(S, C):
  if s == 0 and c == 0 and N != 1:
    print(-1)
    exit()
  if num[s] == '*':
    num[s] = str(c)
  elif num[s] != str(c):
    print(-1)
    exit()

if num[0] == '*' and N != 1:
  num[0] = '1'
print(''.join(num).replace('*', '0'))
Buggy code:
fla = 0
ans = 0

ket , kaz = map(int,input().split())
num = [-1 for i in range(ket)]
for j in range(kaz):
    s , c = map(int,input().split())
    if num[s-1] == -1:
        num[s-1] = c
    elif num[s-1] != c:
        fla = -1
        break

if fla == 0:
    if num[0] == 0:
        if ket != 1 
            fla = -1
    elif num[0] == -1:
        if ket == 1:
            num[0] = 0
        elif ket != 1:
            num[0] = 1

if fla == 0:
    for i in range(ket-1):
        if num[i+1] == -1:
            num[i+1] = 0
            
if fla == 0:
    for h in range(ket):
        ans +=  num[h]*(10**(ket-h-1))
    print(ans)
elif fla == -1:
    print(-1)
    

Fixed code:
fla = 0
ans = 0

ket , kaz = map(int,input().split())
num = [-1 for i in range(ket)]
for j in range(kaz):
    s , c = map(int,input().split())
    if num[s-1] == -1:
        num[s-1] = c
    elif num[s-1] != c:
        fla = -1
        break

if fla == 0:
    if num[0] == 0:
        if ket != 1:
            fla = -1
    elif num[0] == -1:
        if ket == 1:
            num[0] = 0
        elif ket != 1:
            num[0] = 1

if fla == 0:
    for i in range(ket-1):
        if num[i+1] == -1:
            num[i+1] = 0
            
if fla == 0:
    for h in range(ket):
        ans +=  num[h]*(10**(ket-h-1))
    print(ans)
elif fla == -1:
    print(-1)
Buggy code:
n, m = map(int, input().split())

a = [0]*n

for i in range(m):
    s, c = map(int, input().split())
    if a[s-1] == 0:
        a[s-1] = c
    elif a[s-1] != c:
        print(-1)
        exit()
if n != 1 and a[0] == 0:
    a[0] = 1
for i in range(n):
    print(a[i], end="")


Fixed code:
n, m = map(int, input().split())
a = [-1]*n
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:
        print(-1)
        exit()
    if n != 1 and s == 1 and c == 0:
        print(-1)
        exit()
for i in range(n):
    if a[i] == -1:
        a[i] = 0
if n != 1 and a[0] == 0:
    a[0] = 1
for i in range(n):
    print(a[i], end="")
Buggy code:
import sys
N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]

ans = ['-1'] * N

for i in range(M):
    if ans[sc[i][0]-1] == sc[i][1]:
        continue
    elif ans[sc[i][0]-1] == '-1':
        ans[sc[i][0]-1] = sc[i][1]
    else:
        print('-1')
        sys.exit()

if N >= 2:
    if ans[0] == '-1':
        ans[0] == 1
    elif ans[0] == 0:
        print('-1')
        sys.exit()

for i in range(N):
    if ans[i] == '-1':
        print(0)
        sys.exit()

real = 0
for i in ans:
    real = real * 10 + i

print(real)

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

ans = ['-1'] * N

for i in range(M):
    if ans[sc[i][0]-1] == sc[i][1]:
        continue
    elif ans[sc[i][0]-1] == '-1':
        ans[sc[i][0]-1] = sc[i][1]
    else:
        print('-1')
        sys.exit()

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

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

real = 0
for i in ans:
    real = real * 10 + i

print(real)
Buggy code:
# C
N,M=map(int,input().split())
cnd=[tuple(int(i) for i in input().split()) for j in range(M)]
ans=-1
for n in range(10**N-1):
    # print(n)
    flag=True
    n_str=str(n)
    for s,c in cnd:
        if n_str[s-1]!=str(c):
            # print(n_str[s-1],c)
            flag=False
            break
    if flag:
        ans=n
        break
print(ans)

Fixed code:
# C
N,M=map(int,input().split())
cnd=[tuple(int(i) for i in input().split()) for j in range(M)]
ans=-1
for n in range(10**N):
    # print(n)
    flag=True
    n_str=str(n)
    if len(n_str)!= N:
        continue
    for s,c in cnd:
        if n_str[s-1]!=str(c):
            # print(n_str[s-1],c)
            flag=False
            break
    if flag:
        ans=n
        break
print(ans)
Buggy code:
N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

D=[-1]*3
ans=True

for s,c in S:
    if D[s-1] == -1:
        D[s-1]=c
    else:
        if D[s-1] != c:
            ans=False
if D[N-1]==0: ans=False

t=[i if i != -1 else 0 for i in D]

print(''.join(map(str,t)) if ans else -1)

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

D=[-1]*N
ans=True

for s,c in S:
    if D[s-1] == -1:
        D[s-1]=c
    else:
        if D[s-1] != c:
            ans=False

if D[0]==0 and 1<N: ans=False
if D[0]==-1:
    if N==1:
        D[0]=0
    else:
        D[0]=1

for i in range(N):
    if D[i]==-1: D[i]=0 
     
print(''.join(map(str,D)) if ans else -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 i in range(10**N):
    stri = str(i)
    if len(stri) == N and all([stri[S[j]-1] == str([C[j]]) for j in range(M)]):
        print(stri)
        exit()
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)


for i in range(10 ** (N + 1)):
  Str = str(i)

  if len(Str) == N and all([Str[s[j] - 1] == str(c[j]) for j in range(M)]):
      print(Str)
      exit()

print(-1)
Buggy code:
n, m = map(int, input().split())
s = []
c = []
for i in range(n):
  S, C = map(int, input().split())
  s.append(S)
  c.append(C)
for i in range(10 **(n + 1)):
  tmp = str(i)
  if len(tmp) == n and all([tmp[s[j] - 1] == str(c[j]) for j in range(m)]):
    print(tmp)
    exit()
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)
for i in range(10 **(n + 1)):
  tmp = str(i)
  if len(tmp) == n and all([tmp[s[j] - 1] == str(c[j]) for j in range(m)]):
    print(tmp)
    exit()
print(-1)
Buggy code:
n, m = list(map(int, input().split()))
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(0, 10**n):
  str_i = str(i)
  if len(str_i) != n: continue

  chk = True
  for s, c in sc:
    if str_i[s-1] == c:
      cnt &= str_i[s-1] == str(c)
  if chk:
    print(i)
    exit()

  print(-1)
     
    
  

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

for i in range(0, 10**n):
  str_i = str(i)
  if len(str_i) != n: continue

  chk = True
  for s, c in sc:
    chk &= str_i[s-1] == str(c)
  if chk:
    print(i)
    exit()

print(-1)
Buggy code:
n,m=map(int,input().split())
keep=0
aa=["#"]*n
for i in range(m):
  s,c=map(str,input().split())
  s=int(s)
  if aa[s-1]=="#":
    aa[s-1]=c
  elif aa[s-1] !=c:
    keep=1
    print(-1)
    break
if keep==0:
  moji=""
  if aa[0]=="#":
    moji+="1"
  else:
    moji+=aa[0]
  for i in range(1,n):
    if aa[i]=="#":
      moji+="0"
    else:
      moji+=aa[i]
print(moji)

Fixed code:
n,m=map(int,input().split())
keep=0
aa=["#"]*n
for i in range(m):
  s,c=map(str,input().split())
  s=int(s)
  if n>=2 and s==1 and c=="0":
    keep=1
    print(-1)
    break
  if aa[s-1]=="#":
    aa[s-1]=c
  elif aa[s-1] !=c:
    keep=1
    print(-1)
    break
if keep==0:
  moji=""
  if aa[0]=="#" and n>=2:
    moji+="1"
  elif n==1 and aa[0]=="#":
    moji+="0"
  else:
    moji+=aa[0]
  for i in range(1,n):
    if aa[i]=="#":
      moji+="0"
    else:
      moji+=aa[i]
  print(moji)
Buggy code:
import math

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

found = False

for i in range(pow(10,N-1), pow(10,N)):
   
    i_str = str(i)

    passed = True
    for j in range(M):
        if not i_str[s[j]-1] == c[j]:
            passed = False
            break
    if passed:
        found = True
        print(i)

if not found:
    print("-1")

Fixed code:
import math

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

found = False

start = pow(10,N-1)
stop = pow(10,N)
if N == 1:
    start = 0

for i in range(start, stop):
    
    i_str = str(i)

    passed = True
    for j in range(M):
        if not i_str[s[j]-1] == str(c[j]):
            passed = False
            break
    if passed:
        found = True
        print(i)
        break

if not found:
    print("-1")
Buggy code:
N,M=map(int,input().split())

flag=True
ex=[False]*(N)
for i in range(M):
    S,C=map(int,input().split())
    if S>N:
        flag=False
        break
    elif ex[S-1]==False or ex[S-1]==str(C):
        ex[S-1]=str(C)
    else:
        flag=False
        break

if N>1 and ex[0]==0:
    flag=False

if flag:
    for i in range(N-1):
        if ex[i+1]==False:
            ex[i+1]='0'
    if ex[0]==False:
        ex[0]=1
    Ex=''.join(ex)
    print(Ex)
else:
    print(-1)

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

flag=True
ex=[False]*(N)
for i in range(M):
    S,C=map(int,input().split())
    if ex[S-1]==False or ex[S-1]==str(C):
        ex[S-1]=str(C)
    else:
        flag=False
        break

if N>1 and ex[0]==str(0):
    flag=False

if flag:
    for i in range(N-1):
        if ex[i+1]==False:
            ex[i+1]='0'
    if ex[0]==False and N>1:
        ex[0]='1'
    elif ex[0]==False:
        ex[0]='0'
    Ex=''.join(ex)
    print(Ex)
else:
    print(-1)
Buggy code:
N, M = map(int, input().split())
s = []
c = []
check = [-1 for _ in range(N)]
muri = False
for _ in range(M):
    tmp = list(map(int, input().split()))
    s.append(tmp[0])
    c.append(tmp[1])
 
result = [0 for _ in range(N)]
 
for idx, S in enumerate(s):
    if check[S-1] < 0:
        result[S-1] = str(c[idx])
        check[S-1] = c[idx]
        if (S == 1) and c[idx] == 0:
            if N != 1:
                muri = True
                break
    else:
        if check[S-1] != c[idx]:
            muri = True
            break
if result[0] == 0:
    result[0] = 1
a = ''
reigai = True
if N==1 and M==0:
    reigai = True
for i in result:
    a += str(i)
if muri:
    print(-1)
else:
    if reigai:
        print(0)
    else:
        print(int(a))

Fixed code:
N, M = map(int, input().split())
s = []
c = []
check = [-1 for _ in range(N)]
muri = False
for _ in range(M):
    tmp = list(map(int, input().split()))
    s.append(tmp[0])
    c.append(tmp[1])
 
result = [0 for _ in range(N)]
 
for idx, S in enumerate(s):
    if check[S-1] < 0:
        result[S-1] = str(c[idx])
        check[S-1] = c[idx]
        if (S == 1) and c[idx] == 0:
            if N != 1:
                muri = True
                break
    else:
        if check[S-1] != c[idx]:
            muri = True
            break
if result[0] == 0:
    result[0] = 1
a = ''
reigai = False
if N==1 and M==0:
    reigai = True
for i in result:
    a += str(i)
if muri:
    print(-1)
else:
    if reigai:
        print(0)
    else:
        print(int(a))