n,m = map(int,input().split())
digit = [0]*(m)
value = [0]*(m)
for i in range(m):
    digit[i],value[i] = map(int,input().split())

#全探索
ans = 0
keta = 10**(n-1)
for i in range(keta, 10**3):
    s = str(i)
    flag = True
    for j in range(m): 
        if int(s[digit[j]-1]) != value[j]: #違ったらFalse
            flag = False
    if flag:
        ans = i
        break
print(ans if flag else '-1')