n, m = map(int, input().split())
res = ["n" for _ in range(n)]
for _ in range(m):
    s, c = map(int, input().split())
    idx = s - 1
    if res[idx] == "n" or res[idx] == c:
        res[idx] = c
    if res[idx] != "n" and res[idx] != c:
        res = -1
        break
if res == -1: print(res)
else:
    if res[0] == "n":
        if n == 1:
            res[0] = 0
        else:
            res[0] = 1
    for i in range(1, n):
        if res[i] == "n": res[i] = 0
    print(int("".join([str(r) for r in res])))