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

# print(sc)

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

for i in range(m):
    s, c = sc[i]
    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] != "0" and a[i] != c:
        print(-1)
        exit()
    a[s] = c

# print(a)
if a[0] == "0":
    a[0] = 1 
ans = int("".join(a))
print(ans)