N, M = map(int, input().split())
num = [None] * N
FLG = True

for _ in range(M):
    i, digit = map(int, input().split())
    i -= 1
    if num[i] is not None and num[i] != digit:
        FLG = False
    else:
        num[i] = digit

if FLG:
    ans = "".join("0" if i is None else str(i) for i in num)
    if ans == str(int(ans)):
        print(int(ans))
    else:
        print(-1)

else:
    print(-1)
