n, m = list(map(int, input().split(' ')))
val = [-1 for _ in range(n)]
failed = False
for _ in range(m):
    s, c = list(map(int, input().split(' ')))

    if val[s-1] == -1:
        val[s-1] = c
    elif val[s-1] == c:
        val[s-1] = c
    else:
        print(-1)
        failed = True
        break
if val[0] == 0 and not(failed):
    print(-1)
    failed = True
elif val[0] == -1:
    val[0] = 1
out = str(val[0])
if not(failed):
    for i in range(1, n):
        if val[i] == -1:
            val[i] = 0
        out += str(val[i])

    print(int(out))
