n, m = map(int, input().split())
a = ["0"] * n
f = [False] * n
flag = True
for _ in range(m):
    s, c = map(int, input().split())
    if f[s-1] and a[s-1] != str(c):
        flag = False
        break
    f[s-1] = True
    if s > n:
        flag = False
        break
    a[s-1] = str(c)
if a[0] == "0":
    flag = False

print("".join(a) if flag else -1)
