n,m=map(int,input().split())
s=[0]*m
c=[0]*m
t=[]
for i in range(m):
    s[i], c[i]=map(int,input().split())
for i in range(n):
    t.append("0")
for i in range(m):
    t[s[i]-1]=str(c[i])
for i in reversed(range(m)):
    if t[s[i]-1]!=str(c[i]):
        print(-1)
        break
    elif ''.join(t)=="000" or ''.join(t)=="00":
        print(-1)
        break
    elif i==0 and t[0]=="0":
        t[0]="1"
        print(''.join(t))
        break
    elif i==0:
        print(''.join(t))