N,M=map(int,input().split())
S = [None]*M
for i in range(M):
    S[i] = list(map(int,input().split()))
    S[i][0]-=1

ans = [-1]*N
for i in range(M):
    if ans[S[i][0]] != -1 and ans[S[i][0]] != S[i][1]:
        print(-1)
        break
    elif S[i][0] == 0 and S[i][1] == 0:
        print(-1)
        break
    else:
        ans[S[i][0]] = S[i][1]
else:
    if ans[0] == -1:
        ans[0]==1

    for i in range(1,N):
        if ans[i] == -1:
            ans[i] = 0
    for i in range(N):
        print(ans[i],end='')
