def main():
    n, m = list(map(int, input().split()))

    # print("n: ", n)
    # print("m: ", m)


    scs = {}
    answer = ["0" for i in range(n)]

    for i in range(m):
        s, c = list(map(int, input().split()))
        # print("s: ", s)
        # print("c: ", c)
        if ((s in scs) and scs[s] != c) or (c == 0 and s != len(answer)):
            return "-1"
        else:
            scs[s] = c
    # print(scs)
    for k in scs:
        answer[k-1] = str(scs[k])
        # print(answer)
    po = int("".join(answer))
    return po

print(main())