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 1 not in d:
    a[0] = 1
if ok and a[0] != 0:
    print(*a, sep="")
else:
    print(-1)