n, m = (int(x) for x in input().split())
ans = [None for _ in range(n)]
fail = False
for _ in range(m):
    s,c = (int(x) for x in input().split())
    s -=1
    if ans[s] is None:
        ans[s] = c
    elif ans[s] != c:
        fail = True
        break
if fail or ans[0] == 0:
    print(-1)
else:
    if ans[0] is None:
        ans[0] = 1
    print(''.join((str(i) if i is not None else '0' for i in ans)))