import sys
input = sys.stdin.readline

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

num = ["X"]*n
frag = [0]*n
ans = 0
for s, c in sc:
    if frag[s-1] != 0 and num[s-1] != c or s == 1 and c == 0:
        ans = -1
        print(ans)
        break
    elif frag[s - 1] == 0:
        num[s - 1] = c
        frag[s - 1] = 1

if ans != -1:
    for i in range(n):
        if num[i] == "X":
            num[i] = "0"
    for j in range(n):
        print(num[j], end="")
