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

s, c = [], []

for i in range(m):
    a, b = map(int, input().split())
    s.append(a - 1)
    c.append(b)

for i in range(1, 1000):
    now = str(i)
    if len(now) != n:
        continue
    is_condition = True
    for j in range(m):
        if int(now[s[j]]) != c[j]:
            is_condition = False
    if is_condition:
        print(i)
        exit()

print(-1)