from sys import exit

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

ans = [0]*N
mask = [0]*N
for i in range(M):
    s,c = S[i],C[i]
    if mask[s-1]==0:
        mask[s-1] = 1
        ans[s-1] = c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit()

if N==1:
    if mask[0]==1:
        print(*ans,sep='')
    else:
        print(-1)
    exit()

if ans[0]==0:
    print(-1)
    exit()

print(*ans,sep='')