n,m = list(map(int, input().split()))

jouken = {}
ans = ''
for i in range(m):
    s, t = list(map(int, input().split()))
    if s in jouken.keys():
        if jouken[s] != t:
            ans = -1
            break
    else:
        if s == 1 and t == 0:
            ans = -1
            break
        else:
            jouken[s] = t
    
if ans != -1:
    for j in range(n):
        keta = j+1
        if keta in jouken.keys():
            ans += str(jouken[keta])
        elif keta == 1:
            ans += '1'
        else:
            ans += '0'
            
print(int(ans))
