N,M = map(int,input().split())
ls = []
for i in range(M):
    ls1 = list(map(int,input().split()))
    ls.append(list(ls1))
    ls1.clear()
#print(ls)
ans = []
for i in range(10**N):
    #print(i)
    I = str(i)
    cnt = 0
    if len(I) == N:
        for j in range(M):
            #print(i,j)
            if int(I[ls[j][0]-1]) == ls[j][1]:
                cnt += 1
            if cnt == M:
                ans.append(i)
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))
