n,m = [int(x) for x in input().split()]
sc = {}
out = False
for _ in range(m):
    s,c = [x for x in input().split()]
    if s in sc.keys():
        if sc[s] != c:
            print("-1")
            out = True
        else:
            sc[s] = c
    else:
        sc[s] = c
        

if not out:
    for i in range(1,4):
        if not str(i) in sc.keys():
            sc[str(i)] = "0"

    if n == 1 and sc["1"] != "0" and sc["2"] != 0:
        print(sc["1"], sep="")
    elif n == 2 and sc["1"] != "0" and sc["2"] != 0:
        print(sc["1"],sc["2"], sep="")
    elif n == 3 and sc["1"] != "0":
        print(sc["1"],sc["2"],sc["3"], sep="")
    else:
        print("-1")