N,M = map(int,input().split())
ichi = []
ni = []
san = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ichi.append(c)
    elif s == 2:
        ni.append(c)
    else:
        san.append(c)

if N == 1:
    if ichi == []:
        ichi.append(0)
    for i in range(0,10):
        if i in ichi:
            print(i)
            exit()
if N == 2:
    if set(ichi) == set([0,]):
        print(-1)
        exit()
    if ichi == []:
        ichi.append(1)
    if ni == []:
        ni.append(0)
    for i in range(1,10):
        for j in range(0,10):
            if i in ichi and j in ni:
                print(str(i)+str(j))
                exit()
if N == 3:
    if set(ichi) == set([0,]):
        print(-1)
        exit()
    if ichi == []:
        ichi.append(1)
    if ni == []:
        ni.append(0)
    if san == []:
        san.append(0)
    for i in range(1,10):
        for j in range(0,10):
            for k in range(0,10):
                if i in ichi and j in ni and k in san:
                    print(str(i)+str(j)+str(k))
                    exit()
print(-1)
