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

ss = []
cs = []
for i in range(m):
    s,c = map(int,input().split())
    ss.append(s)
    cs.append(c)



tf = True
for i in range(m):
    if (ss[i] == 1) and (cs[i] == 0):
        tf = False
        break
    for j in range(m):
        if (ss[i] == ss[j]) and (cs[i] != cs[j]):
            tf = False
            break

ans = 0
if tf == False:
    print(-1)
else:
    for i in range(1,n + 1):
        if i in ss:
            for j in range(m):
                if ss[j] == i:
                    ans += 10**(n-i) * cs[j]
                    break
    
    print(ans)