n,m=map(int,input().split())
num=[0 for i in range(n)]
ans=0

if n==1:
    for i in range(m):
        s,c=map(int,input().split())
        if c==0:
            ans=-1
        else:
            if ans==0 or num[0]==c:
                num[0]=c
            else:
                ans=1
                break
    if ans!=1:
        print(num[0])
    else:
        print(-1)
else:
    for i in range(m):
        s,c=map(int,input().split())
        if s==1 and c==0:
            ans=1
            break
        if num[s-1]==0 or num[s-1]==c:
            num[s-1]=c
        else:
            ans=1
            break
    
    if ans==0:
        if num[0]==0:
            num[0]=1
        for i in num:
            print(i,end="")
    else:
        print(-1)