N, M = map(int, input().split())
sc = []
for i in range(M):
    s,c = map(int, input().split())
    sc.append([s,c])

ans = 0
sc_dic = {}
for i in sc:
    if i[0] in sc_dic:
        if i[1] != sc_dic[i[0]]:
            ans = -1
    else:
        ans += 10**(N-i[0])*i[1]
        sc_dic[i[0]] = i[1]

if sc_dic[1] == 0:
    ans = -1
print(ans)