import sys
nm =input().rstrip().split(" ")
n =int(nm[0])
m =int(nm[1])
direcs=[]
for i in range(m):
    direcs.append(input().rstrip().split(" "))
#print(direcs)
trdirecs=list(map(list, set(map(tuple, direcs))))
#print(trdirecs)
first=[]
second=[]
third=[]
for j in trdirecs:
    if int(j[0])==1:
        first.append(int(j[1]))
    if int(j[0])==2:
        second.append(int(j[1]))
    if int(j[0])==3:
        third.append(int(j[1]))
if first[0]==0 and (n==2 or n==3):
    answer=-1
    print(answer)
    sys.exit()
    
'''print(first)
print(second)
print(third)'''
'''if len(first)>1 or len(second)>1 or len(third)>1:
    print(-1)'''
if len(first)==0:
    first.append(0)
if len(second)==0:
    second.append(0)
if len(third)==0:
    third.append(0)
#数字が条件を満たしているかどうか判定する
if n==1:
    for i in range(0,10):
        if i==first[0]:
            answer=i
elif n==2:
    for i in range(0,100):
        d1=int((i-i%10)/10)
        d2=i%10
        if d1==first[0] and d2 ==second[0]:
            answer=i
            if answer<=9:
                answer=10+i
elif n==3:
    for i in range(0,1000):
        d3=i%10
        a=int((i-d3)/10)
        d2=a%10
        d1=int((a-a%10)/10)
        #print(d1,d2,d3)
        if d1==first[0] and d2==second[0] and d3==third[0]:
            answer=i
            if answer<100:
                answer=100+i
if len(first)>1 or len(second)>1 or len(third)>1:
    answer=-1
print(answer)