from collections import defaultdict

N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

d = defaultdict(list)
for s, c in SC:
    d[s].append(c)


if any(len(set(v)) > 1 for v in d.values()):
    print(-1)
elif d[1] == [0] and N > 1:
    print(-1)
else:
    ans = [0] * N
    ans[0] = 1
    for i in range(N):
        if d[i + 1]:
            ans[i] = d[i + 1].pop()
            
    print("".join(list(map(str, ans))))







