n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
result = [-1]*n
ans = 0
for el in sc:
    s = el[0]
    c = el[1]
    if s==1 and c==0 and n != 1:
        ans = -1
        break
    elif result[s-1] == -1 or result[s-1] == c:
        result[s-1] = c
    else:
        ans = -1
        break
if ans == -1:
    print(ans)
else:
    if result[0] == -1:
        result[0] = 1
    for i in range(1, len(result)):
        if result[i] == -1:
            result[i] = 0
    i = 0
    for el in result[::-1]:
        ans += el*(10**i)
        i += 1
    print(ans)