from collections import Counter

n,m = map(int,input().split())
l1 = []

for i in range(m):
    l1.append(list(map(int,input().split())))

l1 = list(set(list(map(tuple, l1))))

ans = ''
for i in range(len(l1)):
    for j in range(len(l1)):
        if i < j:
            if l1[i][0] == l1[j][0]:
                ans = -1
                
if n > 1:
    for i in range(len(l1)):
        if l1[i][0] == 1 and l1[i][1] == 0:
            ans = -1
if not ans == -1:
    for i in range(1,n+1):
        new = ''
        for j in range(len(l1)):
            if i == l1[j][0]:
                new = str(l1[j][1])
        if len(new) == 0:
            new = '1'
        ans = ans + new
print(ans)
    