N,M=map(int,input().split())
ans=[0]*N
guess=0
num=0
S=[]
C=[]
for _ in range(M):
    s,c=map(int,input().split())
    S.append(s)
    C.append(c)
for i in range(M):
    s=S[i]
    c=C[i]
    if ans[s-1]!=0 and ans[s-1]!=c:
        guess=1
        break
    elif s==1 and c==0:
        guess=1
        break
    else:
        ans[s-1]=c
if guess==0:
    if ans[0]==0:
        ans[0]=1
    for i in range(N):
        num+=ans[i]*(10**(N-1-i))
    print(num)
else:
    print(-1)