N,M = map(int,input().split())
sc = list([list(map(int,input().split())) for _ in range(M)])


for i in range(10**(N-1)-1,10**N):
    count = 0
    str_i = str(i)
    for j in range(M):
        if str_i[sc[j][0]-1] == str(sc[j][1]):
            count += 1
    if count == M:
        print(i)
        exit()
print(-1)
