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

tmp = []
for _ in range(m):
    tmp.append(tuple(map(int, input().split())))
used = [(-1, -1)]

digits = [0 for _ in range(n)]
out = -1
for s, c in sorted(tmp, key=lambda x: x[0]):
    s_, c_ = used[-1]
    if s == s_:
        if c != c_:
            break
        else:
            continue
    if (s, c) == (1, 0):
        if n > 1:
            break
    digits[s - 1] = c
    used.append((s, c))
else:
    out = int("".join(map(str, digits)))

print(out)
