n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    t, d = map(int, input().split())
    s.append(t)
    c.append(d)
a = -2
for i in range(m-1):
    for j in range(i+1, m):
        if s[i] == s[j]:
            if c[i] != c[j]:
                a = -1
if a == -2:
    if n == 1:
        a = c[0]
    if n == 2:
        for i in range(10, 100):
            b = 0
            for j in range(m):
                if s[j] == 1:
                    if i//10 == c[j]:
                        b += 1
                else:
                    if i%10 == c[j]:
                        b += 1
            if b == m:
                a = i
                break;
    if n == 3:
        for i in range(100, 1000):
            b = 0
            for j in range(m):
                if s[j] == 1:
                    if i//100 == c[j]:
                        b += 1
                elif s[j] == 1:
                    if (i//10)//10 == c[j]:
                        b += 1
                else:
                    if i%10 == c[j]:
                        b += 1
            if b == m:
                a = i
                break;
if a == -2:
    a = -1
print(a)