N, M = map(int, input().split())
number = list()
for i in range(M):
    number.append(list(map(int, input().split())))
   
answer_dict = dict()
check = 0
for i in range(M):
    keta = number[i][0]
    num = number[i][1]
    if keta not in answer_dict.keys():
        answer_dict[keta] = num
    
    elif keta in answer_dict.keys() and answer_dict[keta] != num:
        check = -1
        break


answer_list = list()
for i in range(1, N+1):
    if i == 1:
        if i not in answer_dict.keys() and N >= 2:
            answer_list.append('1')
        elif i not in answer_dict.keys() and N == 1:
            answer_list.append('0')
        elif answer_dict[i] == 0:
            check = -1
        else:
            answer_list.append(str(answer_dict[i]))
    else:
        if i not in answer_dict.keys():
            answer_list.append('0')
        else:
            answer_list.append(str(answer_dict[i]))

if check == -1:
    print(-1)
else:
    print(''.join(answer_list))