ok=True
a,b=map(int,input().split())
val=[]
for i in range(b):
    c,d=map(int,input().split())
    val.append([c,d])
val=sorted(val)
for i in range(b-1):
    if val[i][0]==val[i+1][0] and val[i][1]!=val[i+1][1]:
        ok=False
        print(-1)
        break
if ok:
    e=[0 for i in range(a)]
    strr=""
    for i in val:
        e[i[0]-1]=i[1]
    if e[0]==0:
        if e==[0]:
            print(0)
        for i in range(1,a):
            strr+=str(e[i])
        if set(strr)=={'0'}:
            print(-1)
        else:
            print(int(strr))
    else:
        for i in range(a):
            strr+=str(e[i])
        print(strr)