n,m=map(int,input().split())

markarr=[-1]*n
flag=0
for i in range(m):
    a,b=map(int,input().split())
    if(markarr[a-1]!=-1 and markarr[a-1]!=b):
        flag=1
    markarr[a-1]=b

if(flag==1 or (markarr[0]==0 and n>1)):
    print(-1)
else:
    ans=''
    if(n==1):
        print(markarr[0])
        exit(0)

    elif(markarr[0]==-1):
        ans='1'
    else:
        ans=str(markarr[0])

    for i in range(1,n):
        ans+=str(max(markarr[i],0))
    print(ans)
