size,num = map(int,input().split())

ref = [list(map(int,input().split())) for i in range(num)]

first = -1
second = -1
third = -1

jud = 0


for kk in range(num):
    if ref[kk][0] == 1:
        if first == -1 or first == ref[kk][1]:
            first = ref[kk][1]
        else:
            jud = 1
    elif ref[kk][0] == 2:
        if second == -1 or second == ref[kk][1]:
            second = ref[kk][1]
        else:
            jud = 1
    elif ref[kk][0] == 3:
        if third == -1 or third == ref[kk][1]:
            third = ref[kk][1]
        else:
            jud = 1

if first == 0:
    jud = 1

if jud == 1:
    print(-1)
else:
    if first == -1:
        if size > 1:
            first =1
        else:
            first =0
    if second == -1:
        second =0
    if third == -1:
        third =0

    if size == 1:
        print(first)
    elif size == 2:
        print(str(first*10 + second))
    else:
        print(str(first*100 + second*10 + third))
