from collections import defaultdict

N, M = map(int, input().split())

d = defaultdict(set)
for i in range(M):
    s, c = (map(int, input().split()))
    d[s].add(c)

ans = "9" * N
if not N == 1:
    if not d.get(1, -1) == -1:
        if list(d.get(1, -1))[0] == 0:
            ans = -1
for k in d.keys():
    if len(d.get(k)) > 1:
        ans = -1

min = ""
for digit in range(1,4):
    if digit in d.keys():
        min += str(list(d.get(digit))[0])
    else:
        min += "0"

if int(min) <= int(ans):
    ans = min

print(int(ans))