n, m = map(int, input().split())

digit = [-1] * n
flag = True
for _ in range(m):
    s, c = map(int, input().split())
    if digit[s - 1] == -1 or digit[s - 1] == c:
        digit[s - 1] = c
    else:
        flag = False
        break


if flag and digit[0] != 0:
    for i in digit:
        if i == -1: i = 0
        print(i, end="")
    print("")
else:
    print(-1)