N, M = map(int, input().split())
sc_list = []
for i in range(M):
    sc = list(map(int, input().split()))
    sc_list.append(sc)
ans = -1
if N!=1:
    for i in sc_list:
        if i[0]!=N and i[1]==0:
            print(ans)
            exit()
sc_dic = {}
for i in sc_list:
    if i[0] in sc_dic:
        if sc_dic[i[0]] != i[1]:
            print(ans)
            exit()
    else:
        sc_dic[i[0]] = i[1]
tmp = [str(0) for i in range(N)]
for i in sc_list:
    tmp[i[0]-1] = str(i[1])
print("".join(tmp))
