n,m = map(int,input().split())
sc = [0]*m
for i in range(m):
    sc[i] = list(map(int,input().split()))
ans = 1
k = [-1]*n
for i in range(m):
    if k[sc[i][0]-1] == sc[i][1] or k[sc[i][0]-1] == -1:
        k[sc[i][0]-1] = sc[i][1]
    else:
        ans = 0
        break
if k[0] == 0:
    ans = 0

if ans == 0:
    print(-1)
else:
    for i in range(n):
        if i == 0 and n != 1:
            if k[0] == -1:
                print(1,end="")
            else:
                print(k[0],end="")
        else:
            if k[i] == -1:
                print(0,end="")
            else:
                print(k[i],end="")
    print("")