from collections import defaultdict
n,m=map(int,input().split())
l={}
for i in range(m):
    s,c=map(int,input().split())
    if s not in l:
        l[s]=[c] 
    else:
        l[s].append(c)
    
f,g=True,True 
for x in l:
    if len(set(l[x]))>1:
        f=False
        break 
for x in l:
    if x==1 and 0 in l[x]:
        g=False
        break 
if not f or not g:
    print(-1)
else:
    flag=0
    for i in range(0,1000):
        x=list(map(int,list(str(i))))
        if len(x)==n:
            flag=True
            for y in l:
                if l[y][0]!=x[y-1]:
                    flag=False
                    break 
        if flag==True:
            flag=i 
            break
    if flag:                
        print(flag)
    else:print(-1)
    

    