from collections import defaultdict

n, m = map(int, input().split())
ans = [0]*n

sc = defaultdict(set)

for _ in range(m):
    s, c = map(int, input().split())
    sc[s].add(c)
    ans[s-1] = c


if len(str(int(''.join(map(str, ans))))) != n or not all(len(v) == 1 for v in sc.values()):
    print(-1)
else:
    print(*ans, sep='')
