n,m = map(int,input().split())
ls = []
for i in range(m):
    ls.append(list(map(int,input().split())))

ans = []
for i in range(n):
    ans.append("a")

t = 0
for i in range(m):
    if ans[ls[i][0]-1] == "a":
        ans[ls[i][0]-1] = ls[i][1]
        t += 1
    elif ans[ls[i][0]-1] != ls[i][1]:
        print(-1)
        break
    else:
        t += 1

d = []
if t == m:
    for i in range(n):
        d.append(str(ans[i]))
    for k in range(n):
        if d[k] == "a":
            d[k] = "0"
    if d[0] == "0" :
        if n != 1:
            print(-1)
        else:
            print(0)
    else:
        if n != 1:
            for j in range(1,n):
                d[0] += d[j]
            print(d[0])