N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
ans = [-1]*N
err = 0

for i in range(M):
    if(N>1 and sc[i] == [1,0]):
        err = 1
    elif(ans[sc[i][0]-1] == -1 or ans[sc[i][0]-1] == sc[i][1]):
        ans[sc[i][0]-1] = sc[i][1]
    else:
        err = 1
if(err == 1):
    print("-1")
else:
    if(ans[0] == -1):
        ans[0] = 1
    ans[0] = str(ans[0])
    for i in range(1,N):
        if(ans[i] == -1):
            ans[i] = 0
        ans[i] = str(ans[i])
    print(int("".join(ans)))