N,M = map(int,input().split())
zero = set()
ichi = set()
ni = set()
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        zero.add(c)
    elif s == 2:
        ichi.add(c)
    else:
        ni.add(c)
if zero == set():
    zero.add(0)
if ichi == set():
    ichi.add(0)
if ni == set():
    ni.add(0)
if N == 1:
    for i in range(0,10):
        I = list(str(i))
        if int(I[0]) in zero:
            print(i)
            exit()
elif N == 2:
    for i in range(10,100):
        I = list(str(i))
        if int(I[0]) in zero and int(I[1]) in ichi:
            print(i)
            exit()
else:
    for i in range(100,1000):
       I = list(str(i))
       if int(I[0]) in zero and int(I[1]) in ichi and int(I[2]) in ni:
           print(i)
           exit()
print(-1)
print(zero,ichi,ni)
