n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

# print(sc)

a = ["_" for _ in range(n)]

for i in range(m):
    s, c = sc[i]
    if n < s:
        print(-1)
        exit()
    s -= 1
    if n == 3 and s == 0 and c == 0:
        print(-1)
        exit()
    if n == 2 and s == 1 and c == 0:
        print(-1)
        exit()
    if n == 1 and s == 2 and c == 0:
        print(-1)
        exit()
    c = str(c)
    if i == s and a[i] != "_" and a[i] != c:
        print(-1)
        exit()
    a[s] = c

# print(a)
if n == 1 and a[0] == "_" or a[0] == "0":
    ans = 0
elif a[0] == "_":
    a[0] = "1"
elif a[0] == "0":
    print(-1)
for i in range(n):
    if a[i] == "_":
        a[i] = "0"
ans = int("".join(a))
print(ans)