n, m = map(int, input().split())
s, c = [],[]
kari = list()
for i in range(m):
    kari.append(list(map(int, input().split())))
for i in range(m):
    s.append(kari[i][0])
    c.append(kari[i][1])
kari.sort()
for i in range(m-1):
    if kari[i][0] == kari[i+1][0] and kari[i][1] != kari[i+1][1]:
        print(-1)
        exit()



l = ["0"] * n
for i in range(m):
    if s[i] == 1 and c[i] == 0:
        print(-1)
        exit()
    else:
        l[s[i]-1] = str(c[i])
if l[0] == "0":
    l[0] = "1"
print("".join(l))