import sys
n,m=map(int,input().split())
l=[-1]*(n)
for i in range(m):
    s,c=map(int,input().split())
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        print(-1)
        sys.exit()
if l[0]==0 and len(l)!=1:
    print(-1)
    sys.exit()
for i in range(n):
    if l[i]==-1:
        l[i]=0
if l[0]==0 and len(l)==1:
    l[0]=0

if l[0]==0 and len(l)==1:
    print(0)
else:
    for i in range(n):
        print(l[i],end="")