import sys

n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

d = {1: None, 2: None, 3: None}

for itm in sc:
    if (d[itm[0]] == None) | (d[itm[0]] == itm[1]):
        d[itm[0]] = itm[1]
    else:
        print(-1)
        sys.exit()

l = list(d.values())
l = [0 if x == None else x for x in l]
if l == [0]:
    print(l)
elif l[0] == 0:
    print(-1)
else:
    l = map(str, l)
    print("".join(l))