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