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:
    ans = 0
    for i in range(len(digit)):
        if digit[i] == -1:
            digit[i] = 1 if i == 0 else 0

        ans += 10 ** (n - i - 1) * digit[i]
    print(ans)
else:
    print(-1)