n,m = [int(x) for x in input().split()]
sc = {}
for _ in range(m):
    s,c = [x for x in input().split()]
    sc[s] = c

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

if sc["1"] == "0":
    print("-1")
else:
    ans = [sc[str(x)] for x in range(1,4)]
    print(*ans, sep="")