n, m = map(int, input().split())
s, c = [], []
for _ in range(m):
    _s, _c = map(int, input().split())
    s.append(_s-1)
    c.append(_c)

ans = [float("inf")]*n
for i in range(m):
    if s[i] == 0 and c[i] == 0:
        continue

    if c[i] <= ans[s[i]]:
        ans[s[i]] = c[i]

ans = map(lambda x: 0 if x == float("inf") else x, ans)
ans = int("".join(map(str, ans)))
print(-1 if len(str(ans)) != n else ans)
