n,m=map(int,input().split())

one=-1
two=-1
thr=-1

for i in range(m):
    s,c=map(int,input().split())
    if s==1:
        if one==-1 or one==c:
            one=c
        else:
            print("-1")
            exit()
    elif s==2:
        if two==-1 or two==c:
            two=c
        else:
            print("-1")
            exit()
    else:
        if thr==-1 or thr==c:
            thr=c
        else:
            print("-1")
            exit()

if n==3:
    if one==0 or two==0:
        print("-1")
        exit()
elif n==2:
    if two==0:
        print("-1")
        exit()

if one==-1:
    one=0
if two==-1:
    two=0
if thr==-1:
    thr=0


if n==1:
    for i in range(10):
        if i==thr:
            print(i)
            exit()
elif n==2:
    for i in range(10,100):
        if str(i)[0]==str(two) and str(i)[1]==str(thr):
            print(i)
            exit()
else:
    for i in range(100,1000):
        if str(i)[0]==str(one) and str(i)[1]==str(two) and str(i)[2]==str(thr):
            print(i)
            exit()