A = []
N,M = list(map(int,input().split()))
for i in range(M):
    A.append(list(input().split()))
for i in range(10 ** N):
    str_i = str(i)
    if N == len(str_i):
        for j,k in A:
            if str_i[int(j)-1] == k:
                pass
            else:
                break
        if str_i[int(j)-1] == k:
            print(i)
            exit()
print("-1")