N,M = list(map(int, input().split()))

appeard_digit = {}
ans = ["0"] * N
sc_pair = []
max_digit = -1
for _ in range(M):
    s,c = list(map(int, input().split()))

    if ans[s-1] != "0" and str(c) != ans[s-1]:
        print(-1)
        exit()
    else:
        ans[s-1] = str(c)

if ans[0] == "0" and N>1:
    print(-1)
else:
    print("".join(ans))
