n, m = map(int, input().split())
S = ["0" for i in range(n)]
r = True
all_zero = True
for _ in range(m):
    s, c = map(int, input().split())
    if c != 0:
        all_zero = False
    if (S[s - 1] != str(c) and S[s - 1] != "0") or (s == 1 and c == 0):
        r = False
        pass
    else:
        S[s - 1] = str(c)
if all_zero and n != 1:
    r = False
if S[0] == "0" and not all_zero:
    S[0] = "1"
print("".join(S)) if r else print(-1)
