n,m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]

count = float('inf')
if n == 3:
    for i in range(100, 1000):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                 count = i
elif n == 2:
    for i in range(10, 100):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i
elif n == 1:
    for i in range(0, 10):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i

if count == float('inf'):
    print(-1)
else:
    print(