NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
sc = []
for i in range(M):
    addList = list(map(int, input().split()))
    sc.append(addList)
a = 0
for i in range(100000):
    j = str(i)
    diff = N - len(j)
    for k in range(diff):
        j = '0'+j
    bingo = True
    for l in sc:
        if int(j[l[0]-1]) != l[1]:
            bingo = False
    if bingo:
        break
    else:
        a += 1
if a == 100000 and bingo == False:
    print(-1)
elif len(str(a))>N:
    print(-1)
else:
    print(a)