n, m = [int(i) for i in input().split()]
s = []
c = []
for _ in range(m):
    i, k = [int(i) for i in input().split()]
    s.append(i)
    c.append(k)

res = [-1] * n
ok = True
for i, k in zip(s, c):
    if res[i-1] == -1:
        res[i-1] = k
    elif res[i-1] != k:
        ok = False
        break

ans = [abs(res.pop(0))] if m != 0 else [0]
ans += [0 if i == -1 else i for i in res]
ans = int(''.join([str(i) for i in ans]))
print(ans) if ok and len(str(ans)) == n else print(-1)
