n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1 or a[s]==c:
        a[s]=c
    else:
        print(-1)
        exit()
if a[0]==-1:
    a[0]=1
if a[0]==0:  
    print(-1)
    exit()
b=""
for i in a:
    if i==-1:
        b+="0"
    else:
        b+=str(i)
print(b)  