import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = []
b = [0 for m in range(n)]
r = []
for q in range(m):
    if ls[q][0] == 1:
        r.append(ls[q][1])
if len(set(r)) > 1:
    print(-1)
    sys.exit()
for q in range(m):
    if ls[q][0] == 1:
        if ls[q][1] == 0:
            if n > 1:
                print(-1)
                sys.exit()
            if n == 1:
                print(0)
                sys.exit()
        else:
            b[0] = ls[q][1]
if b[0] == 0:
    b[0] =1
for j in range(2,n+1):
    for k in range(m):
        if ls[k][0] == j:
            a.append(ls[k][1])
    if len(set(a)) ==1:
        c = list(a)
        b[j-1] = c[0]
    elif len(set(a)) >1:
        print(-1)
        sys.exit()
    a = []
t = "".join(map(str,b))
print(t)