N, M = list(map(int, input().split()))
result = ["x"] * N
no_break_check = 1
for i in range(M):
    s, c = list(input().split())
    s = int(s)
    if result[s-1] == "x":
        result[s-1] = c
    elif result[s-1] != c:
        print("-1")
        no_break_check = 0
        break

if no_break_check:
    if N > 1:
        for i, chr in enumerate(result):
            if result[i] == "x":
                if i == "0":
                    result[i] = "1"
                else:
                    result[i] = "0"
        if result[0] == "0":
            print("-1")
        else:
            print(int("".join(result)))
    else:
        if result[0] == "x":
            print(0)
        else:
            print(int(result[0]))