n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
c=0
d=0
a=[]
ans=0
for i in range(m):
    for j in range(1,m):
        if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:
            c=c+1
for i in range(m):
    if l[i][0]==1 and l[i][1]==0:
        d=d+1


for i in range(n+1):
    a.append(0)

for i in range(m):
        a[l[i][0]]=l[i][1]

if d==0 and a[1]==0 and n!=1 and m!=0:
    a[1]=1

if d==0 and a[1]==0 and n!=1 and m==0:
    a[1]=0
if c!=0 or d!=0:
    print("-1")
else:
    for i in range(1,n+1):
        ans=ans+a[i]*10**(n-i)
    print(ans)