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())

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

ans = [0]*N
for i in range(N):
    if k[i]==-1:
        ans[i] = 0
    else:
        ans[i] = k[i]


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

if ans[0]==0:
    ans[0] = 1

print(*ans,sep='')