n,m=map(int,input().split())
 
one=-1
two=-1
thr=-1

if m==0:
    print("-1")
    exit()
 
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:
        print("-1")
        exit()
    elif one==-1 and 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
 
ans=str(one)+str(two)+str(thr)
 
print(int(ans))