N,M = map(int,input().split())
flag = True
answer = [0]*N
answer[0] = 1
change_list = [0]*N
answer_num = 0
for i in range(M):
    num_list = list(map(int,input().split()))
    if change_list[num_list[0]-1] == 0:
        answer[num_list[0]-1] = num_list[1]
        change_list[num_list[0]-1] = 1
    else:
        if answer[num_list[0]-1] == num_list[1]:
            continue
        else:
            flag = False

if flag == False:
    print(-1)

if answer[0] == 0:
    print(-1)
else:
    for i in range(len(answer)):
        answer_num += 10**(len(answer) - (i+1))*answer[i]
    print(answer_num)