n,m = map(int,input().split())
s_c_list=[list(map(int,input().split())) for _ in range(m)]

ans_list = [0 for _ in range(n)]

cant_count = 0
for i in range(len(s_c_list)):
    if s_c_list[i][0] == 1 and s_c_list[i][1] == 0:
        cant_count += 1
    else:
        if ans_list[s_c_list[i][0] - 1] == 0:
            ans_list[s_c_list[i][0] - 1] = s_c_list[i][1]
        elif ans_list[s_c_list[i][0] - 1] != s_c_list[i][1]:
            cant_count += 1

ans_list_final = []
non0_count = 0
for i in range(len(ans_list)):
    if non0_count == 0:
        if ans_list[i] != 0:
            non0_count += 1
            ans_list_final.append(ans_list[i])
    else:
        ans_list_final.append(ans_list[i])
        
s = ''
for i in range(len(ans_list_final)):
    s += str(ans_list_final[i])

if cant_count == 0:
    print(s)
else:
    print('-1')