qyliang/CodeNanoFix huggingface dataset:
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)

flag = True
x = 0

for i in range(1000):
    x = i
    d = []
    flag = True
    if x == 0:
        d.append(x)
    while x != 0:
        num = x % 10
        d.append(num)
        x = x // 10
    d = d[::-1]
    for j in range(m):
        try:
            if d[S[j]-1] == C[j]:
                pass
            else:
                flag = False
        except IndexError:
            flag = False
    if flag:
        x = i
        break
print(x if flag else -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)

flag = True
x = 0

for i in range(1000):
    x = i
    d = []
    flag = True
    if x == 0:
        d.append(x)
    while x != 0:
        num = x % 10
        d.append(num)
        x = x // 10
    d = d[::-1]
    if len(d) != n:
        flag = False
    for j in range(m):
        try:
            if d[S[j]-1] == C[j]:
                pass
            else:
                flag = False
        except IndexError:
            flag = False
    if flag:
        x = i
        break
print(x if flag else -1)
Buggy code:
N,M = map(int,input().split())
flag = True
answer = [0]*N
answer[0] = 1
change_list = [0]*N
answer_num = 0
for i in range(M):
    num_list = list(map(int,input().split()))
    if change_list[num_list[0]-1] == 0:
        answer[num_list[0]-1] = num_list[1]
        change_list[num_list[0]-1] = 1
    else:
        if answer[num_list[0]-1] == num_list[1]:
            continue
        else:
            flag = False

if flag == False:
    print(-1)

if answer[0] == 0:
    print(-1)
else:
    for i in range(len(answer)):
        answer_num += 10**(len(answer) - (i+1))*answer[i]
    print(answer_num)

Fixed code:
N,M = map(int,input().split())
flag = True
answer = [0]*N
if len(answer) != 1:
    answer[0] = 1
change_list = [0]*N
answer_num = 0
for i in range(M):
    num_list = list(map(int,input().split()))
    if change_list[num_list[0]-1] == 0:
        answer[num_list[0]-1] = num_list[1]
        change_list[num_list[0]-1] = 1
    else:
        if answer[num_list[0]-1] == num_list[1]:
            continue
        else:
            flag = False

if flag == False:
    print(-1)

elif (answer[0] == 0)&(len(answer) != 1):
    print(-1)
else:
    for i in range(len(answer)):
        answer_num += 10**(len(answer) - (i+1))*answer[i]
    print(answer_num)
Buggy code:
N,M = map(int,input().split())

ans = [-1] * N

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

if N != 1 :
    if ans[0] == 0 :
        print(-1)
        exit()
    if ans[0] == -1 :
        ans[0] = 1
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
else :
    if ans[0] == -1 :
        ans[0] = 0

print(*ans,sep='')


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

ans = [-1] * N

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

if N != 1 :
    if ans[0] == 0 :
        print(-1)
        exit()
    if ans[0] == -1 :
        ans[0] = 1
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
else :
    if ans[0] == -1 :
        ans[0] = 0

print(*ans,sep='')
Buggy code:
N, M=map(int, input().split())
ans=["-1"]*M
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  a="".join(ans)
  b=a.replace("-1", "1")
  print(b)
   

Fixed code:
N, M=map(int, input().split())
ans=["-1"]*N
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0 and N!=1:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  if ans[0]=="-1" and N!=1:
    ans[0]="1"
  elif M==0 and N==1:
    ans[0]="0"
  a="".join(ans)
  b=a.replace("-1", "0")
  print(b)
Buggy code:
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for v in range(m):
        r = input()
        s, c = map(int, r1.split(" "))
        v[s] = c
        if v[s] != "~" and v[s] != c:
            print(-1)
            return
    for x in range(len(v)):
        if v[x] == '~':
            v[x] = 0
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(sv) != len(res_str):
        print(-1)
        return
    print(res_str)

main()
    

Fixed code:
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for t in range(m):
        r = input()
        s, c = map(int, r.split(" "))
        s -= 1
        if v[s] != "~" and v[s] != str(c):
            print(-1)
            return
        v[s] = str(c)
    if n >= 2 and v[0] == '~':
        v[0] = "1"
    for x in range(n):
        if v[x] == '~':
            v[x] = "0"
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(res_str) != n:
        print(-1)
        return
    print(res_str)

main()
Buggy code:
def int_values(slr):
    l, r = map(lambda s: int(s), slr)
    return l, r


def conv_digits(N, digits):
    for i in range(N):
        if digits[i] is None:
            digits[i] = '0' if i == 0 and N == 1 else '1'

    return ''.join(digits)


def main():
    N, M = int_values(input().split())
    digits = [None] * N
    valid = True

    for i in range(M):
        ss = input().split()
        s = int(ss[0])
        c = ss[1]
        if s == 1 and c == '0':
            valid = False
        elif digits[s - 1] is None:
            digits[s - 1] = c
        else:
            valid = digits[s - 1] == c

    if valid:
        print(conv_digits(N, digits))
    else:
        print('-1')


if __name__ == "__main__":
    main()


Fixed code:
def int_values(slr):
    l, r = map(lambda s: int(s), slr)
    return l, r


def conv_digits(N, digits):
    for i in range(N):
        if digits[i] is None:
            digits[i] = '0' if i > 0 or N == 1 else '1'

    return ''.join(digits)


def main():
    N, M = int_values(input().split())
    digits = [None] * N
    valid = True

    for i in range(M):
        ss = input().split()
        s = int(ss[0])
        c = ss[1]
        if N > 1 and s == 1 and c == '0':
            valid = False
        elif digits[s - 1] is None:
            digits[s - 1] = c
        else:
            valid = digits[s - 1] == c

    if valid:
        print(conv_digits(N, digits))
    else:
        print('-1')


if __name__ == "__main__":
    main()
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())
  
max_s=max(s)
ans=-1

for j in range(1000):
  flag=True
  k=str(j)
  if len(k)<max_s:
    pass
  else:    
    for l in range(M):
      if int(k[s[l]-1])!=c[l]:
        flag=False
        break
    if flag==True:
      ans=j
      break
      
print(ans)

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

if M==0:
  for j in range(1000):
    k=str(j)
    if len(k)==N:
      ans=j
      break
else:
  max_s=max(s)
  ans=-1
  for j in range(1000):
    flag=True
    k=str(j)
    if len(k)!=N:
      pass
    else:
      for l in range(M):
        if int(k[s[l]-1])!=c[l]:
          flag=False
          break
      if flag==True:
        ans=j
        break
      
print(ans)
Buggy code:
import sys
n,m=list(map(int,input().split()))
ans=[-1 for i in range(n)]
num=0
for i in range(m):
  s,c=list(map(int,input().split()))
  if n==1 and c==0:
    print(0)
    sys.exit()
  if s==1 and c==0:
    print(-1)
    sys.exit()
  if ans[s-1]==-1 or ans[s-1]==c:
    ans[s-1]=c
  else:
    print(-1)
    sys.exit()

  sys.exit()
if ans[0]==-1:
  ans[0]=1
for i in range(1,n):
  if ans[i]==-1:
    ans[i]=0
ans=map(str, ans)
print("".join(ans))

  

Fixed code:
import sys
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 s==1 and c==0:
    print(-1)
    sys.exit()
  if ans[s-1]==-1 or ans[s-1]==c:
    ans[s-1]=c
  else:
    print(-1)
    sys.exit()

    
if n==1 and (ans[0]==0 or ans[0]==-1):
  print(0)
  sys.exit()
if ans[0]==-1:
  ans[0]=1
for i in range(1,n):
  if ans[i]==-1:
    ans[i]=0
ans=map(str, ans)
print("".join(ans))
Buggy code:
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

for i in range(1000):
    ans = str(i)
    for s, c in sc:
        print(s, c, ans)
        if int(ans[s-1]) != c:
            break
    else:
        print(ans)
        exit()

print(-1)

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

for i in range(1000):
    ans = str(i)
    if len(ans) != n:
        continue
    for s, c in sc:
        if int(ans[s-1]) != c:
            break
    else:
        print(ans)
        exit()

print(-1)
Buggy code:
import sys
n,m = map(int,input().split(" "))
nums = [0] * m
for _ in range(m):
    s,c = map(int,input().split(" "))
    if nums[s-1] != 0 and c != nums[s-1]:
        print(-1)
        sys.exit(0)
    nums[s-1] = c
if nums[0] == 0:
    nums[0] = 1
print("".join(map(str,nums)))

Fixed code:
import sys
n,m = map(int,input().split(" "))
nums = [-1] * n
for _ in range(m):
    s,c = map(int,input().split(" "))
    if n > 1 and s == 1 and c == 0:
        print(-1)
        sys.exit(0)
    if nums[s-1] != -1 and c != nums[s-1]:
        print(-1)
        sys.exit(0)
    nums[s-1] = c
nums = [0 if num == -1 else num for num in nums]
if n == 1:
    print(nums[0])
    sys.exit(0)
if nums[0] == 0:
    nums[0] = 1
print("".join(map(str,nums)))
Buggy code:
n,m=map(int,input().split())
a=[]
for _ in range(m):
    s,c=map(int,input().split())
    a.append([s,c])

ans='-1'
for i in range(10**n):
    x=str(i)
    c=0
    for j in range(m):
        if x[a[j][0]-1] == str(a[j][1]):
            c+=1
    if c==m:
        ans=i
        break
print(ans)

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

ans=-1
if n==1:
    for i in range(10):
        x=str(i)
        c=0
        for j in range(m):
            if x[a[j][0]-1] == str(a[j][1]):
                c+=1          
        if c==m:
            ans=i
            break
else:
    for i in range(10**(n-1),10**n):
        x=str(i)
        c=0
        for j in range(m):
            if x[a[j][0]-1] == str(a[j][1]):
                c+=1          
        if c==m:
            ans=i
            break
print(ans)
Buggy code:
N, M = map(int, input().split())
ans_list=[]
S=[]
C=[]
ans=0
for i in range(M):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for n in range(1000):
  if n < N:
    break
  for i, s in enumerate(S):
    n = str(n)
    if n[s-1] == C[i]:
      continue
    else:
      ans = -1
      break
      
  ans_list.append(int(n))
  
if ans != -1:
  ans=min(ans_list)
  
print(ans)
  

Fixed code:
N, M = map(int, input().split())
ans_list=[]
S=[]
C=[]
ans=0

for i in range(M):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)
#print(S,C)
for n in range(1000):
  flag=0
  if len(str(n)) != N:
    continue
  for i, s in enumerate(S):
    n = str(n)
    if int(n[s-1]) == C[i]:
      continue
    else:
      flag=1
      break
  if flag == 0:
    ans_list.append(int(n))
#print(ans_list)
if len(ans_list) == 0:
  ans = -1
if ans != -1:
  ans=min(ans_list)
  
print(ans)
Buggy code:
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if: flg[s[j]-1] == 1 and ans[s[j]-1] != c[j]:
        print(-1)
        exit()
    else:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    
if n > 1 and ans[0] == 0 :
    print(-1)
else:
    print(''.join(map(str,ans)))


Fixed code:
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if flg[s[j]-1] == 1 and ans[s[j]-1] != c[j]:
        print(-1)
        exit()
    else:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    
if n > 1 and flg[0] == 1 and ans[0] == 0 :
    print(-1)
elif n > 1 and flg[0] == 0:
    ans[0] = 1
    print(''.join(map(str,ans)))
    exit()
else:
    print(''.join(map(str,ans)))
Buggy code:
n,m=map(int,input().split())
L=[10]*n
print(L)
for i in range(m):
	s,c=map(int,input().split())
	if L[s-1]==10 or L[s-1]==c:
		L[s-1]=c
		print(L)
	else:
		print(-1)
		exit()
if n==1:
	if L[0]==10:
		print(0)
		exit()
	else:
		print(L[0])
		exit()
else:
	if L[0]==10:
		L[0]=1
	elif L[0]==0:
		print(-1)
		exit()
	else:
		for i in range(1,n):
			if L[i]==10:
				L[i]=0
	print(''.join(map(str,L)))

Fixed code:
n,m=map(int,input().split())
L=[10]*n
for i in range(m):
	s,c=map(int,input().split())
	if L[s-1]==10 or L[s-1]==c:
		L[s-1]=c
	else:
		print(-1)
		exit()
if n==1:
	if L[0]==10:
		print(0)
		exit()
	else:
		print(L[0])
		exit()
else:
	if L[0]==10:
		L[0]=1
	elif L[0]==0:
		print(-1)
		exit()
	for i in range(1,n):
	    if L[i]==10:
	        L[i]=0
	print(''.join(map(str,L)))
Buggy code:
N, M = map(int, input().split())
ans = [-1]*N
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:
        print(-1)
        break

if len(ans) == 1:
    print(0)
else:
    if ans[0] == 0:
        print(-1)
    elif ans[0] == -1:
        ans[0] = 1
        for i in range(1, M):
            if ans[i] == -1:
                ans[i] = 0
        print(int(''.join(map(str,ans))))

Fixed code:
N, M = map(int, input().split())
ans = [-1]*N
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:
        print(-1)
        exit()
if N == 1:
    if ans[0] == -1:
        print(0)
    else:
        print(int(''.join(map(str,ans))))
else:
    if ans[0] == 0:
        print(-1)
        exit()
    elif ans[0] == -1:
        ans[0] = 1
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
    print(int(''.join(map(str,ans))))
Buggy code:
N, M = map(int,input().split())
ans = list("x"*N)
for i in range(M):
    s,c = map(int,input().split())
    if ans[s-1] == str(c) or ans[s-1] == "x":
        ans[s-1] = str(c)
    else:
        print(-1)
        exit()
if ans[0] == "x":
    ans[0] = "1"
for i in range(N):
    if ans[i] == "x":
        ans[i] = "0"
print("".join(ans))

Fixed code:
N, M = map(int,input().split())
ans = list("x"*N)
for i in range(M):
    s,c = map(int,input().split())
    if ans[s-1] == str(c) or ans[s-1] == "x":
        ans[s-1] = str(c)
    else:
        print(-1)
        exit()
if ans[0] == "0" and N > 1:
    print(-1)
    exit()
if ans[0] == "x" and N > 1:
    ans[0] = "1"
for i in range(N):
    if ans[i] == "x":
        ans[i] = "0"
print("".join(ans))
Buggy code:
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')

Fixed code:
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1:
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')
Buggy code:
n,m = map(int,input().split())

x = []
y = []
ans = [10]*n 

for i in range(m):
    s = input().split()
    x.append(int(s[0]))
    y.append(int(s[1]))

cnt = 0

q = 0

for i in x:
    if i == 1 and y[cnt] == 0 and n!=1:
        print(-1)
        q = 1
        break
    else:
        if ans[i-1] !=10:
            if ans[i-1]==y[cnt]:
                cnt += 1
            else:
                print(-1)
                q = 1
                break
        else:
            ans[i-1] = y[cnt]
            cnt += 1
            
cnt2 = 0

if q ==0:
    for i in ans:
        if i == 10:
            ans[cnt2] = 1
        cnt2 += 1
    for i in ans:
        print(i,end = "")

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

x = []
y = []
ans = [10]*n 

for i in range(m):
    s = input().split()
    x.append(int(s[0]))
    y.append(int(s[1]))

cnt = 0

q = 0

for i in x:
    if i == 1 and y[cnt] == 0 and n!=1:
        print(-1)
        q = 1
        break
    else:
        if ans[i-1] !=10:
            if ans[i-1]==y[cnt]:
                cnt += 1
            else:
                print(-1)
                q = 1
                break
        else:
            ans[i-1] = y[cnt]
            cnt += 1
            
cnt2 = 0

if q ==0:
    for i in ans:
        if i == 10:
            if cnt2 == 0:
                if n == 1:
                    ans[cnt] = 0
                else:
                    ans[cnt2] = 1
            else:
                ans[cnt2] = 0
        cnt2 += 1
    for i in ans:
        print(i,end = "")
Buggy code:
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if t != N:
        continue
    ok = True
    for s, c in sc:
        if t[int(s)] != int(c):
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)


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

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if int(t[s - 1]) != c:
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)
Buggy code:
N,M=map(int,input().split())
ans=10**(N-1)
if M==0:
    print(ans)
else:
    S=[]
    C=[]
    for i in range(M):
        s,c=map(int,input().split())
        S.append(s)
        C.append(c)
    for i in range(1000):
        flag=True
        I=str(i)
        for j in range(M):
            if N<S[j]:
                flag=False
            else:
                if I[S[j]-1]!=str(C[j]):
                    flag=False
        if flag==True:
            print(i)
            exit()
    print(-1)

Fixed code:
N,M=map(int,input().split())
if M==0:
    if N==1:
        print(0)
    else:
        print(10**(N-1))
else:
    S=[]
    C=[]
    for i in range(M):
        s,c=map(int,input().split())
        S.append(s)
        C.append(c)
    if N==1:
        o=0
    else:
        o=10**(N-1)
    for i in range(o,10**N):
        flag=True
        I=str(i)
        for j in range(M):
            if N<S[j]:
                flag=False
            else:
                if I[S[j]-1]!=str(C[j]):
                    flag=False
        if flag==True:
            print(i)
            exit()
    print(-1)
Buggy code:
import sys

N, M = tuple(int(n) for n in input().split())

str_list = ['0' for n in range(N)]
str_state = [0 for n in range(N)] #0 if digit unchanged, 1 if changed

#print(str_list)
#print(str_state)

for i in range(M):
    si, ci = tuple(int(n) for n in input().split())
    print('si: %d, ci: %d' % (si, ci))
    ci = str(ci)
    if str_state[si - 1] == 0:
        str_list[si - 1] = ci
        str_state[si - 1] = 1
        #print(str_list)
        #print(str_state)
    elif str_list[si - 1] != ci:
        #print(-1)
        sys.exit(0)
    #else:
    #    pass

for i in range(len(str_list)):
    if str_list[i] != '0':
        break
    else:
        if str_state[i] == 0:
            str_list[i] = '1'
            break

num = str(int(''.join(str_list)))
if len(num) == N:
    print(num)
else:
    print(-1)


Fixed code:
import sys

N, M = tuple(int(n) for n in input().split())

str_list = ['0' for n in range(N)]
str_state = [0 for n in range(N)] #0 if digit unchanged, 1 if changed

#print(str_list)
#print(str_state)


for i in range(M):
    si, ci = tuple(int(n) for n in input().split())
    #print('si: %d, ci: %d' % (si, ci))
    ci = str(ci)
    if str_state[si - 1] == 0:
        str_list[si - 1] = ci
        str_state[si - 1] = 1
        #print(str_list)
        #print(str_state)
    elif str_list[si - 1] != ci:
        print(-1)
        sys.exit(0)
    #else:
    #    pass

for i in range(len(str_list)):
    if str_list[i] != '0':
        break
    else:
        if i == len(str_list) - 1:
            break
        if str_state[i] == 0:
            str_list[i] = '1'
            break

num = str(int(''.join(str_list)))
if len(num) == N:
    print(num)
else:
    print(-1)
Buggy code:
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    ss,cc = map(int,input().split())
    s.append(ss)
    c.append(cc)
for i in range(10**(n-1) if n>1 else 0,10**n):
    ans = str(i)
    for j in range(m):
        if ans[s[j]-1] != str(c[j]):
            break
        else:
            print(ans)
print(-1)

Fixed code:
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    ss,cc = map(int,input().split())
    s.append(ss)
    c.append(cc)
for i in range(10**(n-1) if n!=1 else 0,10**n):
    ans = str(i)
    for j in range(m):
        if ans[s[j]-1] != str(c[j]):
            break
    else:
        print(ans)
        break
else:        
    print(-1)
Buggy code:
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=range(10**(N-1),10**N)
if N==1:A+=[0]
for i in :
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)

Fixed code:
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=list(range(10**(N-1),10**N))
if N==1:A=[0]+A
for i in A:
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)
Buggy code:
n,m=map(int,input().split())
l=[-1]*n
flag=0
for _ in range(m):
    i,el=map(int,input().split())
    if l[i-1]==-1 :
        l[i-1]=el
    elif l[i-1]==el:
        continue
    else:
        flag=1
        break
if(flag==1):
    print(-1)
else:
    
    if l[0]==-1:
        l[0]=1;
    for i in range(1,len(l)):
        if l[i]==-1:
            l[i]=0
    for i in l:
        print(i,end="")

Fixed code:
n,m=map(int,input().split())
l=[-1]*n
flag=0
for _ in range(m):
    i,el=map(int,input().split())
    if i==1 and el==0 and n!=1:
        flag=1
        break
    if l[i-1]==-1 :
        l[i-1]=el
    elif l[i-1]!=el:
        flag=1
        break
if(flag==1):
    print(-1)
elif m==0 and n==1:
    print(0)
else:
    if l[0]==-1:
        l[0]=1;
    for i in range(1,len(l)):
        if l[i]==-1:
            l[i]=0
    for i in l:
        print(i,end="")
Buggy code:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = ['A'] * N
for i, (si, ci) in enumerate(sc):
    if ans[si - 1] != 'A' and ans[si - 1] != str(ci):
        ans = -1
        break
    #
    ans[si - 1] = str(ci)

if ans == -1:
    print(ans)
else:
    ans = ''.join(ans).replace('A', '1')
    if ans[0] == '0':
        if N == 1:
            print(ans)
        else:
            print(-1)
    else:
        print(ans)

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

ans = ['A'] * N
for i, (si, ci) in enumerate(sc):
    if ans[si - 1] != 'A' and ans[si - 1] != str(ci):
        ans = -1
        break
    #
    ans[si - 1] = str(ci)

if ans == -1:
    print(ans)
else:
    for i in range(N):
        if ans[i] == 'A':
            if N == 1:
                ans[i] = '0'
            else:
                ans[i] = '1' if i == 0 else '0'
    #
    if ans[0] == '0':
        if N == 1:
            print(0)
        else:
            print(-1)
    else:
        print(''.join(ans))