n,m = [int(x) for x in input().split()]
li = list()
for i in range(m):
    li.append([int(x) for x in input().split()])

for i in range(1000):
    length = len(str(i))
    for j in li:
        if (length<j[0] or length<n):
            break
        if (str(i)[j[0]-1] != str(j[1])):
            break
    else :
        print(i)
        break
else:
    print("-1")