N,M=map(int,input().split())
ans=0
digit=[-1]*N
for i in  range(M):
    s,c=map(int,input().split())
    if digit[s-1]>=0 and digit[s-1]!=c:
        ans=-1
        break
    if s==1 and c==0:
        ans=-1
        break
    else:
        digit[s-1]=c

if ans!=-1:
    ans+=max(1,digit[0])*(10**(N-1))
    for j in range(1,N):
        if digit[j]!=-1:
            ans+=digit[j]*(10**(N-j-1))


print(ans)