n, m, *s = map(int, open(0).read().split())
c = s[1::2]
s = s[::2]
s = sorted(set(zip(s, c)))
if s[0][1] == 0:
    print(-1)
    exit()
if sum(s[x][0] == s[x + 1][0] for x in range(len(s) - 1)):
    print(-1)
    raise SystemExit(0)
p = tuple(map(lambda x: x[0], s))
for x in range(1, s[-1][0] + 1):
    if x not in p:
        s.append((x, 0))
s = sorted(s)
print("".join(map(lambda x: str(x[1]), s)))