n,m = map(int,input().split())
digit = [0]*m
num = [0]*m
for i in range(m):
    digit[i], num[i] = map(int, input().split())
for i in range(1000):
    dum = str(i)
    flag = "ok"
    for j in range(m):
        #print(j)
        if len(dum) >= (digit[j]):
            if dum[digit[j]-1] != str(num[j]):
                flag = "ng"
                break
        else:
            flag = "ng"
            break
    if flag == "ok":
        print(dum)
        break
else:
    print(-1)