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)]
print(b)
for q in range(m):
    if ls[q][0] == 1:
        print("Hi")
        if ls[q][1] == 0:
            if n != 1:
                print(-1)
                sys.exit()
            else:
                print(0)
                sys.exit()
        else:
            b[0] = ls[q][1]
for j in range(2,n+1):
    for k in range(m):
        if ls[k][0] == j:
            a.append(ls[k][1])
        else:
            continue
        if len(set(a)) ==1:
            c = list(a)
            b[j-1] = c[0]
        elif len(set(a)) >1:
            print(-1)
            sys.exit()
t = "".join(map(str,b))
print(t)