# -*- coding: utf-8 -*-
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append([int(i) for i in input().split()])

if n == 1:
    count = 0
    for i in range(0, 10):
        tmp1 = i
        flag = True
        for j in range(m):
            if sc[j][0] == 1 and sc[j][1] != tmp1:
                flag = False
        if flag:
            print(i)
            break
        else:
            count += 1
    if count == 9:
        print(-1)

if n == 2:
    count = 0
    for i in range(10, 100):
        tmp1 = i // 10
        tmp2 = i - (tmp1 * 10)
        tmp = 0
        flag = True
        for j in range(m):
            if sc[j][0] == 1 and sc[j][1] != tmp1:
                flag = False
            if sc[j][0] == 2 and sc[j][1] != tmp2:
                flag = False
        if flag:
            print(i)
            break
        else:
            count += 1
    if count == 90:
        print(-1)

if n == 3:
    count = 0
    for i in range(100, 1000):
        tmp1 = i // 100
        tmp2 = (i - tmp1 * 100) // 10
        tmp3 = i - tmp1 * 100 - tmp2 * 10
        flag = True
        for j in range(m):
            if sc[j][0] == 1 and sc[j][1] != tmp1:
                flag = False
            if sc[j][0] == 2 and sc[j][1] != tmp2:
                flag = False
            if sc[j][0] == 3 and sc[j][1] != tmp3:
                flag = False
        if flag:
            print(i)
            break
        else:
            count += 1
    if count == 900:
        print(-1)