n, m = map(int, input().split())
l, l1, l2 = list(""), list(""), list("")
s1, s2 = set(""), set("")
for i in range(n):
    l.append(0)
for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        print("-1")
        exit()
    l1.append(s)
    l2.append(c)
    s1.add(s)
    s2.add(c)
if len(s1) != len(s2):
    print("-1")
    exit()
for i in range(len(l1)):
        l[l1[i] - 1] = l2[i]
if l[0] == 0 and n != 1:
    l[0] = 1
a = ''
for i in range(n):
    a += str(l[i])
print(a)