from collections import Counter

N, M = map(int, input().split())
s = []
c = []

for i in range(M):
    l = input().split()
    s.append(l[0])
    c.append(l[1])

flag = 0
for i in range(M):
    for j in range(M):
        if i != j:
            if s[i] == s[j] and c[i] != c[j]:
                flag == 1
                break

if flag == 0:
    for i in range(1000):
        flag2 = 0
        cand = list(str(i).zfill(3))
        #print(cand)
        if len(cand) == N:
            for j in range(M):
                if cand[int(s[j])-1] != c[j]:
                    flag2 = 1
                    break
            if flag2 == 0:
                print(i)
                break
    if flag2 == 1:
        print(-1)
else:
    print(-1)
