import sys
n,m = map(lambda x: int(x),input().split())
ans = list('z'*(n))
kotae = 0
for i in range(m) :
    s,c = map(lambda x: int(x),input().split())
    if (s == 1 and c == 0 ) or (s > n) or (ans[s-1] != str(c) and ans[s-1] != 'z'):
        print(-1)
        sys.exit()
    ans[s - 1] = str(c)

for j in range(n) :
    if j == 0 and ans[j] == 'z' and n > 1:
        kotae += 10**(n-j -1)

    else :
        if ans[j] != 'z':
            kotae += int(ans[j])*10**(n-j -1)




print(kotae)
