nm = input().split(" ")

n = int(nm[0])
m = int(nm[1])

sc = []

for i in range(m):
    sc.append(input().split(" "))

ans = []

for i in range(10**(n-1), (10**n)-1):
    c = 0
    ia = str(i)
    for j in range(m):
        if sc[j][1] == ia[int(sc[j][0])-1]:
            c = c + 1
    if c == m:
        ans.append(i)

if ans == []:
    print("-1")
else:
    print(min(ans))
