N,M =map(int,input().split())
judge = [list(map(int,input().split())) for i in range(M)]
def Num(x):
    xl = list(str(x))
    xr = []
    for i in range(len(xl)):
        xr.append(int(xl[i]))
    return xr
An = -1
for j in range(10**(N-1),10**N):
    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)