n, m = map(int, input().split())

jouken_1 = []
jouken_2 = []
jouken_3 = []

if m == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    else:
        print(100)
        exit()

for _ in range(m):
    array = tuple(map(int, input().split()))
    if array[0] == 1:
        jouken_1.append(array)
    elif array[0] == 2:
        jouken_2.append(array)
    elif array[0] == 3:
        jouken_3.append(array)

a = set(jouken_1)
b = set(jouken_2)
c = set(jouken_3)
a = list(a)
b = list(b)
c = list(c)

if len(a) > 1:
    print(-1)
    exit()
elif len(a) == 1:
    a = a[0][1]
else:
    a = 0

if len(b) > 1:
    print(-1)
    exit()
elif len(b) == 1:
    b = b[0][1]
else:
    b = 0

if len(c) > 1:
    print(-1)
    exit()
elif len(c) == 1:
    c = c[0][1]
else:
    c = 0

if n == 1:
    if b > 0 or c > 0:
        print(-1)
        exit()
    for i in range(10):
        if i == a:
            print(a)
            exit()
elif n == 2:
    if c > 0:
        print(-1)
        exit()
    for i in range(10, 100):
        if str(i)[0] == str(a) and str(i)[1] == str(b):
            print(i)
            exit()
elif n == 3:
    for i in range(100, 1000):
        if str(i)[0] == str(a) and str(i)[1] == str(b) and str(i)[2] == str(c):
            print(i)
            exit()