N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(M):
    ans[sc[i][0]-1] = str(sc[i][1])

sc.sort()
for i in range(M-1):
    if (sc[i][0] == sc[i+1][0]):
        if (sc[i][1] != sc[i+1][1]):
            f = False

if (f):
    for i in range(M):
        ans[i] = str(ans[i])

    if (ans[0] == "0"):
        if (N == 1):
            print(0)
        else:
            print(-1)
    else:
        print("".join(ans))
else:
    print(-1)