n, m = map(int, input().split())
a = [0] * n
d = {}
ok = True
for i in range(m):
    s, c = map(int, input().split())
    if s not in d or d[s] == c:
        d[s] = c
        a[s - 1] = c
    else:
        ok = False
if ok == False or len(a) != 1 and a[0] == 0:
    print(-1)
else:
    print(*a, sep="")