n,m = [int(i) for i in input().split()]
dict1 = {}
if n!=1:
    dict1[1]=1
else:
    dict1[1]=0
for i in range(1,n):
    dict1[i+1]=0
list1 = []
for i in range(m):
    si,mi = [int(i)for i in input().split()]
    if si==1 and mi==0:
        print(-1)
        break
    if not(si in list1):
        dict1[si]=mi
    else:
        if mi!=dict1[si]:
            print(-1)
            break
    list1.append(si)
else:
    num = ""
    for i in range(1,n+1):
        num+=str(dict1[i])
    print(int(num))