n,m= list(map(int, input().split()))
ans=[0]*n
z=[0]*n
su=0
l=[]
flag=0
for k in range(m):
    a,b= list(map(int, input().split()))
    a-=1
    if z[a]==0:
        z[a]+=1
        ans[a]=b
    else:
        if ans[a]!=b:
            flag=1
            break
if flag==1:
    print(-1)
elif n!=1 and ans[0]==0:
    print(-1)
else:
    for j in reversed(ans):
        l.append(j)
    for k in range(n):
        su+=l[k]*(10**k)
    print(su)