n,m=map(int,input().split())
a=[-1]*n

flag=True
for i in range(m):
    s,c=map(int,input().split())
    if a[s-1]!=c and a[s-1]<0:
        a[s-1]=c
    elif a[s-1]!=c and a[s-1]>=0:
        flag=False
        print(-1)
        break
if flag:
    for i in range(1,n):
        if a[i]==-1:
            a[i]=0
    if a[0]==-1 and n==1:
        a[0]=0
    elif a[0]==-1 and n>1:
        a[0]=1
    elif a[0]==0:
        print(-1)
        flag=False

ans=''
if flag:
    for i in range(n):
        ans+=str(a[i])
    print(ans)
