N,M = map(int,input().split())
e = 0
li = [0]* N
for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    if li[s] == 0:
        li[s] = c
    if li[s] != c:
        e = 1
    if (s == 1) and (c == 0):
        e = 1
if li[0] == 0:
    li[0] = 1
if e == 1:
    print("-1")
    exit()
a = ""
for i in li:
    a += str(i)
print(a)
