qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, m = map(int, input().split())
scs = []
for i in range(m):
    scs.append(list(map(int, input().split())))
    
def set_number(scs):
    number = [-1] * n
    for sc in scs:
        if number[sc[0] - 1] == -1:
            number[sc[0] - 1] = sc[1]
        elif number[sc[0] - 1] != sc[1]:
            return None
    return number
  
def guess_number(number):
    if number is None:
        return -1

    if number[0] == 0:
        return -1
    
    guess = 0
    for i in range(n):
        if i == 0 and  number[i] == 0:
            guess += (10 ** (n - i - 1))
        else:
            guess += number[i] * (10 ** (n - i - 1))

    return guess
  
number = set_number(scs)
print(guess_number(number))

Fixed code:
n, m = map(int, input().split())
scs = []
for i in range(m):
    scs.append(list(map(int, input().split())))
    
def set_number(scs):
    number = [-1] * n
    for sc in scs:
        if number[sc[0] - 1] == -1:
            number[sc[0] - 1] = sc[1]
        elif number[sc[0] - 1] != sc[1]:
            return None
    return number
  
def guess_number(number):
    if number is None:
        return -1

    if number[0] == 0 and n > 1:
        return -1
    
    guess = 0
    for i in range(n):
        if i == 0 and  number[i] == -1 and n == 1:
            return 0
        elif i == 0 and  number[i] == -1:
            guess += (10 ** (n - i - 1))
        elif number[i] != -1:
            guess += number[i] * (10 ** (n - i - 1))

    return guess

number = set_number(scs)
print(guess_number(number))
Buggy code:
def main():
    N , M = map(int,input().split())
    val = [map(int,input().split()) for _ in range(M)]
    ans = [-1 for _ in range(N)]
    flag = True
    for i in range(M):
        p,q = val[i]
        if ans[p-1] != -1 and ans[p - 1] != q :
                flag = False
        ans[p-1] = q
    ans_val = 0
    for i in range(N):
        if ans[i] != -1 :
            ans_val += ans[i] * (10 ** (N - 1 -i))

    if (not flag):
        print(-1)
    else:
        print(ans_val)

if __name__ == '__main__':
    main()

Fixed code:
def main():
    N , M = map(int,input().split())
    val = [map(int,input().split()) for _ in range(M)]
    ans = [-1 for _ in range(N)]
    flag = True
    for i in range(M):
        p,q = val[i]
        if ans[p-1] != -1 and ans[p - 1] != q :
            flag = False
        if ans[p -1] == -1 :
            ans[p-1] = q
    ans_val = 0
    if ans[0] == -1 and N >= 2:
        ans[0] = 1
    for i in range(N):
        if ans[i] != -1 :
            ans_val += ans[i] * (10 ** (N - 1 -i))

    if (ans[0] == 0 and N != 1):
        print(-1)
    elif  (not flag) :
        print(-1)
    else:
        print(ans_val)

if __name__ == '__main__':
    main()
Buggy code:

N,M=map(int,input().split())
slist=[]
for i in range(M):
    slist.append(list(map(int,input().split())))
ans=["0"]*N


for i in range(len(slist)):
    print("i",i)
    if ans[slist[i][0]-1] == "0":
        ans[slist[i][0]-1] = slist[i][1]
    elif ans[slist[i][0]-1] != slist[i][1]:
        ans=["-1"]
        break

#print(ans)

if ans[0]=="0":
    ans[0]=1
if N>=2 and ans[0]==0:
    ans=["-1"]
    
for i in range(len(ans)):
    if ans[i]=="0":
        ans[i]=0

print(*ans,sep=(""))

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

ans=["0"]*N

for i in range(M):
    if ans[slist[i][0]-1]=="0":
        ans[slist[i][0]-1]=slist[i][1]
    elif ans[slist[i][0]-1]!=slist[i][1]:
        ans=["-1"]
        break



if N>1:
    if ans[0]=="0":
        ans[0]=1
    elif ans[0]==0:
        ans=["-1"]
        

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

print(*ans,sep=(""))
Buggy code:
N, M = [int(i) for i in input().split(" ")]
conds = []
for _ in range(M):
    conds.append([int(i) for i in input().split(" ")])

exists = True
A = [None for _ in range(N)]
for s, c in conds:
    idx = s-1
    if A[idx] != None and A[idx] != c:
        exists = False
        break
    A[idx] = c


def check():
    if not exists:
        return [-1]

    if N == 1:
        if A[0] == None:
            return [0]
        else:
            return A
    else:
        if A[0] == 0:
            return [-1]

    for i in range(N):
        if A[i] == None:
            A[i] = -float("infinity")

    base = [1] + [0] * (N-1)
    res = []
    for i in range(N):
        res[i] = max(A[i], base[i])
    return res


print("".join(str(x) for x in check()))


Fixed code:
N, M = [int(i) for i in input().split(" ")]
conds = []
for _ in range(M):
    conds.append([int(i) for i in input().split(" ")])

exists = True
A = [None for _ in range(N)]
for s, c in conds:
    idx = s-1
    if A[idx] != None and A[idx] != c:
        exists = False
        break
    A[idx] = c


def check():
    if not exists:
        return [-1]

    if N == 1:
        if A[0] == None:
            return [0]
        else:
            return A
    else:
        if A[0] == 0:
            return [-1]

    for i in range(N):
        if A[i] == None:
            A[i] = -float("infinity")

    base = [1] + [0] * (N-1)
    res = []
    for i in range(N):
        res.append(max(A[i], base[i]))
    return res


print("".join(str(x) for x in check()))
Buggy code:
N, M = map(int, input().split())
sc = []
for i in range(M):
    sp, cp = map(int, input().split())
    sc.append((sp, cp))

ans = 10000

for i in range(10 * N):
    num = str(i)
    flag = True
    for pair in sc:
        if (num[pair[0] - 1] != pair[1]) or len(i) < pair[0]:
            flag = False
            break
    if flag:
        ans = min(ans, i)

if ans == 10000:
    ans = -1
print(ans)

Fixed code:
N, M = map(int, input().split())
sc = []
for i in range(M):
    sp, cp = map(int, input().split())
    sc.append((sp, cp))

ans = 10000

if N == 1:
    for i in range(10):
        num = str(i)
        flag = True
        for pair in sc:
            if (num[pair[0] - 1] != str(pair[1])):
                flag = False
                break
        if flag:
            ans = min(ans, i)
else:
    for i in range(10 ** (N - 1), 10 ** N):
        num = str(i)
        flag = True
        for pair in sc:
            if (num[pair[0] - 1] != str(pair[1])) or len(num) < pair[0]:
                flag = False
                break
        if flag:
            ans = min(ans, i)

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


li = ["#"]*N
A = "#"
if N==1:
    s,c = map(int,input().split())
    if not c==A and not c=="#":
        print(-1)
        break
    else:
        A=c
else:   
    if A == "#":
        print(0)
    else:
        print(int(A))
    

for i in range(M):
    s,c = map(int,input().split())
    if s==1 and c==0:
        print(-1)
        break

    if not li[s-1]=="#" and not li[s-1]==c:
        print(-1)
        break
    if li[s-1]=="#":
        li[s-1]=c
    
else:
    if li[0]=="#":
        li[0]=1
        
    num="".join(map(str,li))
    num_new=num.replace("#","0")
    print(num_new)

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


li = ["#"]*N
A = "#"
if N==1:
    for i in range(M):
        s,c = map(int,input().split())
        if not c==A and not A=="#":
            print(-1)
            exit()
        else:
            A=c
  
    if A == "#":
        print(0)
    else:
        print(int(A))
    exit()
    

for i in range(M):
    s,c = map(int,input().split())
    if s==1 and c==0:
        print(-1)
        break

    if not li[s-1]=="#" and not li[s-1]==c:
        print(-1)
        break
    if li[s-1]=="#":
        li[s-1]=c
    
else:
    if li[0]=="#":
        li[0]=1
        
    num="".join(map(str,li))
    num_new=num.replace("#","0")
    print(num_new)
Buggy code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,M = LI()
    SC = [LI() for _ in range(M)]
    a = [0 for _ in range(N)]
    pre = [None for _ in range(N)]
    for s,c in SC:
        s = s-1
        if (a[s]==c) or (pre[s] is None):
            pre[s] = a[s]
            a[s] = c
        else:
            print(-1)
            exit(0)
    ans = int("".join(map(str,a)))
    if len(str(ans))==N:
        for i in range(N):
            if pre[i] is None:
                continue
            else:
                pass
        else:
            print(-1)
        print("{}".format(int(ans)))
    else:
        print(-1)
main()



Fixed code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,M = LI()
    SC = [LI() for _ in range(M)]
    a = [0 for _ in range(N)]
    pre = [None for _ in range(N)]
    # for s,c in SC:
    #     s = s-1
    #     if (a[s]==c) or (pre[s] is None):
    #         pre[s] = a[s]
    #         a[s] = c
    #     else:
    #         print(-1)
    #         exit(0)
    # ans = int("".join(map(str,a)))
    # if len(str(ans))==N:
    #     print("{}".format(int(ans)))
    # else:
    #     print(-1)

    for i in range(1000):
        i = str(i)
        if len(i)==N:
            for s,c in SC:
                if i[s-1] == str(c):
                    # print(i[s-1], c)
                    continue
                else:
                    break
            else:
                print(i)
                exit(0)
        else:
            continue
    else:
        print(-1)

main()
Buggy code:
n, m = map(int,input().split())
n_list = []

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

n_list = list(tuple(sorted(n_list)))

keta = [-1 for i in range(n)]
flag = 0

for i in range(len(n_list)):
    if keta[n_list[i][0]-1] == -1:
        keta[n_list[i][0]-1] = n_list[i][1]
    elif keta[n_list[i][0]-1] == n_list[i][1]:
        continue
    else:
        flag = 1
        break

if flag == 1 or (n == 3 and keta[0] == 0) or (n == 2 and keta[0] == 0):
    print(-1)
else:
    if len(keta) == 1:
        if keta[0] == -1:
            print(0)
        else:
            print(keta[0])
    elif len(keta) == 2:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        print(keta[0]*10 + keta[1])
    else:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        if keta[2] == -1:
            keta[2] = 0
        print(keta[0]*100 + keta[1]*10 + keta[0])


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

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

n_list = list(tuple(sorted(n_list)))

keta = [-1 for i in range(n)]
flag = 0

for i in range(len(n_list)):
    if keta[n_list[i][0]-1] == -1:
        keta[n_list[i][0]-1] = n_list[i][1]
    elif keta[n_list[i][0]-1] == n_list[i][1]:
        continue
    else:
        flag = 1
        break

if flag == 1 or (n == 3 and keta[0] == 0) or (n == 2 and keta[0] == 0):
    print(-1)
else:
    if len(keta) == 1:
        if keta[0] == -1:
            print(0)
        else:
            print(keta[0])
    elif len(keta) == 2:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        print(keta[0]*10 + keta[1])
    else:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        if keta[2] == -1:
            keta[2] = 0
        print(keta[0]*100 + keta[1]*10 + keta[2])
Buggy code:
import math


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

max_value = 10 ** n


def check(s):
    for i in range(len(S)):
        if(len(s)<=S[i]):
            return False
        if(int(s[S[i]])!=int(C[i])):
            return False
    return True


def solve():
    for i in range(max_value):
        s = str(i)
        if check(s):
            return i
    return -1


print(str(solve()))


Fixed code:
import math


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

max_value = 10 ** n
min_value = 10 ** (n-1)

if n == 1:
    min_value = 0

def check(s):
    for i in range(len(S)):
        if(int(s[S[i]])!=int(C[i])):
            return False
    return True


def solve():
    for i in range(min_value,max_value):
        s = str(i)
        if check(s):
            return i
    return -1


print(str(solve()))
Buggy code:
N, M = map(int, input().split())
sc = [[int(i) for i in input().split()] for j in range(M)]

num_min = 10**(N-1)
num_max = 10**N
if N > 1:
    i = num_min
else:
    i = 0
ans = -1
while i < num_max:
    num_list = []
    rem = i
    for j in range(N, 0, -1):
        num_list.append(rem // 10**(j-1))
        rem = i % 10**(j-1)
    
    found = True
    for k in range(M):
        s, c = sc[k]
        if num_list[s-1] != c:
            found = False
    
    if found:
        ans = i
        break
    else:
        i += 1

print(num_list)
print(ans)

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

num_min = 10**(N-1)
num_max = 10**N
if N > 1:
    i = num_min
else:
    i = 0
ans = -1
while i < num_max:
    num_list = []
    rem = i
    for j in range(N, 0, -1):
        num_list.append(rem // 10**(j-1))
        rem = i % 10**(j-1)
    
    found = True
    for k in range(M):
        s, c = sc[k]
        if num_list[s-1] != c:
            found = False
    
    if found:
        ans = i
        break
    else:
        i += 1

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


for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    flg=True
    for j in arr:
        if t[j[0]-1] != str(j[i]):
            flg=False
            break

    if flg:
        print(i)
        exit()

print(-1)


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

for i in range(1000):
    s = str(i)
    if len(s) != N:
        continue

    flg = True
    for j in range(len(arr)):
        if s[arr[j][0]-1] != str(arr[j][1]):
            flg = False
            break

    if flg:
        print(i)
        exit()

print(-1)
Buggy code:
p,q= input().split()
a,b =(int(p), int(q))
ans =''
num_list =[]
pare_list=[]
for i in range(b):
    c = map(int,input().split())
    pare_list.append(list(c))
    num_list.append(pare_list[i][0])

search_list = list(range(a*10**3))[10**(a-1):10**(a)]


ans_list=[]
for i in search_list:
    count = 0
    ans_str = str(i)
    
    for j in range(b):
        
        if pare_list[j][1]==int(ans_str[num_list[j]-1]):
            count +=1
        else:
            break
        
        if count == len(num_list):
            ans_list.append(i)
            break

if len(ans_list)>=1:
    print(ans_list[0])
else:
    if a == 1 and b ==0:
        print(0)
    elif a== 1 and pare_list[0][1]==0:
        print(0)
    elif pare_list.count([1, 0]) == b:
        print(10**(a-1))
    
    else:
        print(-1)

Fixed code:
p,q= input().split()
a,b =(int(p), int(q))
ans =''
num_list =[]
pare_list=[]
for i in range(b):
    c = map(int,input().split())
    pare_list.append(list(c))
    num_list.append(pare_list[i][0])

search_list = list(range(a*10**3))[10**(a-1):10**(a)]


ans_list=[]
for i in search_list:
    count = 0
    ans_str = str(i)
    
    for j in range(b):
        
        if pare_list[j][1]==int(ans_str[num_list[j]-1]):
            count +=1
        else:
            break
        
        if count == len(num_list):
            ans_list.append(i)
            break

if len(ans_list)>=1:
    print(ans_list[0])
else:
    if a == 1 and b ==0:
        print(0)
    elif a== 1 and pare_list[0][1]==0:
        print(0)
    elif a>= 2 and b==0:
        print(10**(a-1))
    
    
    else:
        print(-1)
Buggy code:
n, m = map(int, input().split())
l = [0]*n

for _ in range(m):
    a, s = map(int, input().split())
    s = str(s)
    if (l[a-1] and l[a-1] != s) or (a==1 and s=="0"):
        l = -1
        break
    else:
        l[a-1] = s

if l == -1:
    print(l)
else:
    print("".join(l))

Fixed code:
n, m = map(int, input().split())
l = [0]*n

for _ in range(m):
    a, s = map(int, input().split())
    s = str(s)
    if n == 1 and (a==1 and s=="0"):
        l[0] = s
    elif (l[a-1] and l[a-1] != s) or (a==1 and s=="0"):
        l = [-1]
        break
    else:
        l[a-1] = s

num = "".join(map(str, l))

if num[0] == "0" and n != 1:
    print("1" + num[1:])
else:
    print(num)
Buggy code:
# C
N, M = list(map(int, input().split()))

flag = 0
ans = [0]*M
ans_flag = [0]*M

sc = [list(map(int, input().split())) for _ in range(M)]
for i in range(M):
    s, c = sc[i]
    if ans_flag[s-1] == 1:
        if ans[s-1] != c:
            flag = 1
            break
    ans_flag[s-1] = 1
    ans[s-1] = c

if flag == 1:
    print("-1")
else:
    if ans[0] == 0 and ans_flag[0]==1:
        print("-1")
    else:
        if ans[0]==0:
            ans[0] = 1
        print(ans)  

    


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

flag = 0
ans = [0]*N
ans_flag = [0]*N

sc = [list(map(int, input().split())) for _ in range(M)]
for i in range(M):
    s, c = sc[i]
    if ans_flag[s-1] == 1:
        if ans[s-1] != c:
            flag = 1
            break
    ans_flag[s-1] = 1
    ans[s-1] = c

if flag == 1:
    print("-1")
else:
    if N==1:
        for i in ans:
            print(i, end="")

    elif ans[0] == 0 and ans_flag[0]==1:
        print("-1")
    else:
        if ans[0]==0:
            ans[0] = 1
        for i in ans:
            print(i, end="")
Buggy code:
n,m = map(int,input().split())
ans = [0]*n
for i in range(n):
    s,c = map(int,input().split())
    if ans[s-1] == 0 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == 0:
    print(-1)
    exit()
print("".join([str(n) for n in ans]))

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


print("".join([str(i) for i in ans]))
Buggy code:
N, M = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(M)]
ans = [-1] *N
call = True
for k in range(M):
    if ans[num[k][0] -1] == -1 or ans[num[k][0] -1] == num[k][1]:
        ans[num[k][0] -1] = num[k][1]
    else:
        call = False
        break

if call == True:
    if N != 1:
        ans = [0 if a == -1 else a for a in ans]
        if ans[0] == 0:
            ans[0] = 1
        print(''.join(map(str,ans)))
    else:
        if ans[0] == -1:
            print(0)
        else:
            print(''.join(map(str,ans)))
else:
    print(-1)

Fixed code:
N, M = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(M)]
ans = [-1] *N
call = True
for k in range(M):
    if ans[num[k][0] -1] == -1 or ans[num[k][0] -1] == num[k][1]:
        ans[num[k][0] -1] = num[k][1]
    else:
        call = False
        break

if call == True:
    
    if N != 1:
        if ans[0] == 0:
            print(-1)
        else:
            ans = [0 if a == -1 else a for a in ans]
            if ans[0] == 0:
                ans[0] = 1
            print(''.join(map(str,ans)))
    else:
        if ans[0] == -1:
            print(0)
        else:
            print(''.join(map(str,ans)))
else:
    print(-1)
Buggy code:
def main():
    n, m = list(map(int, input().split()))
    dcon = [set() for _ in range(n)]
    for _ in range(m):
        s, c = tuple(map(int, input().split()))
        dcon[s-1].add(c)

    if any(len(d) > 1 for d in dcon):
        print(-1)
        return
    
    digits = [0] if n == 1 else [1] + [0] * (n-1)
    for i in range(n):
        if d:
            digits[i] = d.pop()

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

main()


Fixed code:
def main():
    n, m = list(map(int, input().split()))
    dcon = [set() for _ in range(n)]
    for _ in range(m):
        s, c = tuple(map(int, input().split()))
        dcon[s-1].add(c)

    if any(len(d) > 1 for d in dcon):
        print(-1)
        return
    
    digits = [0] if n == 1 else [1] + [0] * (n-1)
    for i in range(n):
        if dcon[i]:
            digits[i] = dcon[i].pop()

    if digits[0] == 0 and n != 1:
        print(-1)

    else:
        print(''.join(map(str, digits)))

main()
Buggy code:
def main():
    n, m = map(int, input().split())
    ans = [0]*n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s-1] == 0:
            ans[s-1] = c
        elif ans[s-1] != 0 and ans[s-1] != c:
            print(-1)
            exit()

    if len(ans[0]) == 1:
        print(*ans, sep="")
    if ans[0] == 0:
        print(-1)
    else:
        print(*ans, sep="")


if __name__ == "__main__":
    main()


Fixed code:
def main():
    n, m = map(int, input().split())
    ans = [-1]*n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != -1 and ans[s-1] != c:
            print(-1)
            exit()

    if n == 1:
        if ans[0] == -1:
            ans[0] = 0
    else:
        if ans[0] == 0:
            print(-1)
            exit()

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

        for i in range(1, n):
            if ans[i] == -1:
                ans[i] = 0
    print(*ans, sep="")


if __name__ == "__main__":
    main()
Buggy code:
a,b=map(int,input().split())
ans=-1
arr = [list(map(int,input().split)) for i in range(b)]

for i in range(1001):
  j=str(i)
  if len(j)==a and all(j[s-1]==str(t) for s,t in arr):
    ans = i
    break
print(ans)

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

for i in range(1001):
  j=str(i)
  if len(j)==a and all(j[s-1]==str(t) for s,t in arr):
    ans = i
    break
print(ans)
Buggy code:
N, M = map(int, input().split())
Z = [None for _ in range(N)]
for i in range(M):
  s, c = map(int, input().split())
  if Z[s-1] == None or Z[s-1] == c:
    Z[s-1] = c
  else:
    print(-1)
    break
else:
  if Z[0] == 0:
    print(-1)
  elif Z[0] == None:
    Z[0] = 1
    for l in range(N):
      if Z[l] == None:
        Z[l] = 0
    print("".join(map(str, Z)))

Fixed code:
N, M = map(int, input().split())
Z = [None for _ in range(N)]
for i in range(M):
  s, c = map(int, input().split())
  if Z[s-1] == None or Z[s-1] == c:
    Z[s-1] = c
  else:
    print(-1)
    break
else:
  if N == 1 and (M == 0 or Z[0] == 0):
    print(0)
  elif Z[0] == 0:
    print(-1)
  elif Z[0] == None:
    Z[0] = 1
    for l in range(N):
      if Z[l] == None:
        Z[l] = 0
    print("".join(map(str, Z)))
  else:
    for p in range(N):
      if Z[p] == None:
        Z[p] = 0
    print("".join(map(str, Z)))