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 = [0]*n
for i in range(m):
    if c[i] > ans[s[i]]:
        ans[s[i]] = c[i]

ans = int("".join(map(str, ans)))
print(-1 if len(str(ans)) != n else ans)
