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

if len(set(s)) != len(set(c)):
    print(-1)
    quit()

ans = ["0"]*n
for i in range(m):
    ans[s[i]-1] = c[i]

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