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 = {}
min_s = N+1
for i in sc:
    min_s = min(min_s, i[0])
    if i[0] in sc_dic:
        if i[1] != sc_dic[i[0]]:
            ans = -1
            break
        break
    else:
        ans += 10**(N-i[0])*i[1]
        sc_dic[i[0]] = i[1]

if ans != -1:
    if 1 not in sc_dic:
        ans += 10**(N-1)
        sc_dic[1] = 1
        min_s = 1

    if min_s in sc_dic:
        if sc_dic[min_s] == 0:
            ans = -1
    if min_s == N+1:
        if N == 1:
            ans = 0
        else:
            ans = 10**(N-1)
print(ans)