n,m = map(int,input().split())
L = [input().split() for i in range(m)]

for i in range(m):
    L[i] = [int(x) for x in L[i]]
    
flag = False
for i in range(100,1000):
    i = str(i)
    for j in range(m):
        if i[L[j][0]-1] == str(L[j][1]):
            flag = True
        else:
            flag = False
            break
    if flag:
        print(i)
        exit()
print(-1)