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

tmp = [-1] * n
hantei = True

for _ in range(m):
    s, c = map(int, input().split())
    if tmp[s-1] == -1 or tmp[s-1] == c:
        tmp[s-1] = c
    else:
        hantei = False


if tmp[0] == -1:
    tmp[0] = 1
else:
    if tmp[0] == 0:
        hantei = False

for i in range(n):
    if tmp[i] == -1:
        tmp[i] = 0


ans = 0
if hantei:
    for i in range(0, n)[::-1]:
        ans += int(tmp[(n-i-1)]) * (10**i)
    print(ans)
else:
    print(-1)