import sys
n, m = map(int, input().split(" "))
ans = [-1]*n
for _ in range(m):
    s, c = map(int, input().split(" "))
    if s == 1 and c == 0:
        print("-1")
        sys.exit()
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] == c:
        pass
    else:
        print("-1")
        sys.exit()

if ans[0] == 0 and len(ans) > 0:
    ans[0] = 1

print("".join(map(str, [ 0 if x == -1 else x for x in ans])))