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

cnt = [-1] * n
ans = -1
cnt_sc = [-1] * n
for i in sc:
    cnt_sc[i[0] - 1] = 1

for i in range(n):
    if cnt_sc[i] == -1:
        if i == 0:
            sc.append([i+1, 1])
        else:
            sc.append([i+1, 0])

for i in range(1000):
    if sum(cnt) == 0:
        break
    lst = []
    tmp = i
    while i > 0:
        lst.append(i % 10)
        i //= 10
    lst.reverse()

    cnt = [-1]*m
    if len(lst) != n:
        continue
    for j in sc:
        if lst[j[0] - 1] == j[1]:
            cnt[j[0] - 1] = 0
    ans = tmp

print(ans)
