n,m = map(int,input().split())
L = []
for i in range(m):
    L.append(list(((map(int,input().split())))))
#print(L)
if L == False:
    print(-1)
    exit()
li = [-1]*n
dic = {}
for i in range(m):
    if L[i][0] not in dic:
        dic[L[i][0]] = L[i][1]
#print(dic)
for i in range(m):
    if dic[L[i][0]] != L[i][1]:
        print(-1)
        exit()
    li[L[i][0]-1] = L[i][1]
#print(li)
if n == 1:
    print(li[0])
    exit()
else:
    for i in range(m):
        if li[i] == -1:
            li[i] = 0
    if li[0] == 0:
        print(-1)
        exit()
    else:
        li = [str(x) for x in li]
print("".join(li))