N, M = map(int, input().split())
sc = [input().split() for i in range(M)]
cand = ["a","a","a"]
#print(sc)

for i in range(M):
    if cand[int(sc[i][0])-1] == "a":
        cand[int(sc[i][0])-1] = sc[i][1]
    elif cand[int(sc[i][0])-1] != "a" and cand[int(sc[i][0])-1] == sc[i][1]:
        cand[int(sc[i][0])-1] = sc[i][1]


for i in range(3):
    if cand[i] == "a":
        cand[i] = "0"
num = str(int("".join(cand)))
if len(num) == N:
    print(int("".join(cand)))
else:
    print("-1")