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)
    try:
        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()
    except IndexError:
        print("-1")
        exit()
print("-1")