import sys
n,m=map(int,input().split())
a=[-1 for i in range(n)]

for i in range(m):
    s,c=map(int,input().split())
    s-=1

    if n!=1 and s==0 and c==0:
        print(-1)
        sys.exit()

    if a[s]!=-1 and a[s]!=c:
        print(-1)
        sys.exit()
    else:
        a[s]=c


if n==1 and a[0]==0:
    print(0)
    sys.exit()

x=""
if a[0]==-1: a[0]=1
for i in range(n):
    if a[i]==-1: a[i]=0
    x+=str(a[i])
print(x)
    
