N,M = map(int,input().split())
S,C = [],[]
for i in range(M):
    s,c = map(int,input().split())
    S.append(s)
    C.append(c)

for i in range(10**N):
    stri = str(i)
    if len(stri) == N and all([stri[S[j]-1] == str([C[j]]) for j in range(M)]):
        print(stri)
        exit()
print(-1)
