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

l = list()
for i in range(1000):
    i = str(i).zfill(3)
    flg = True
    for j in sc:
        if int(i[j[0]-1]) != j[1]:
            flg = False
    if flg:
        l.append(int(i))

print(min(l) if len(l) != 0 else -1)