N,M =map(int,input().split())
judge = [list(map(int,input().split())) for i in range(M)]
def Num(x):
    if x >= 100:
        return [x//100, x//10-(x//100)*10,x-(x//100)*100-((x//10-(x//100)*10)*10)]
    elif x >= 10:
        return [-1,x//10,x-(x//10)*10]
    else:
        return [-1, -1, x]
An = -1
for j in range(0,10**N+1):
    if An != -1:
        break
    Numi = Num(j)
    A = 0
    for i in range(M):
        if Numi[judge[i][0]-1] != judge[i][1]:
            break
        A += 1
        if A == M:
            An = j
print(An)