n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]
if (1,0) in sc:
    return -1
for s, c in sc:
    if ans[s-1] and ans[s-1]!=c:
        return -1
    else:
        ans[s-1]=c
if not ans[0]:
    return -1
_ans = ""
print(_ans.lstrip('0'))