from sys import exit
N, M = map(int, input().split())
S = ["0"] * N
done = [False] * N

for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and N > 1:
        print(-1)
        exit()
    if not done[s-1]:
        S[s-1] = str(c)
        done[s-1] = True
    elif S[s-1] == str(c):
        continue
    else:
        print(-1)
        exit()
if not done[0] and N != 1:
    S[0] == "1"
print("".join(S))
