n,m  = map(int, input().split())
t = [0]*n
for _ in range(m):
    s, c = map(int, input().split())
    if t[s-1] == 0 or t[s-1] == c:
        t[s-1] = c
    else:
        print(-1)
        break
else:
    if t[0] == 0 and n != 1:
        print(-1)
    else:
        print(int("".join(map(str, t))))