n,m = map(int,input().split())

c = []
for i in range(m):
    c.append(list(map(int,input().split())))

max = 0
for i in range(m):
    if c[i][0] >= max:
        max = c[i][0]

ans = -1
for i in range(pow(10,max-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i

print(ans)  