n, m = map(int, input().split())
digits = [None] * n
f = False
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if digits[s] == None and digits[s] == c and not (s == 1 and c == 0):
        digits[s] = c
    else:
        f = True

if f:
    print(-1)
else:
    for i in digits:
        print(i if i != None else 0, end='')
