figure, condition_num = [int(n) for n in input().rstrip().split()]

candidate_num = [-1]*figure

for _ in range(condition_num):
    from_left, num = [int(n) for n in input().rstrip().split()]
    from_left-=1
    if candidate_num[from_left] ==-1:
        candidate_num[from_left] = num
    elif candidate_num[from_left]!=num:
        candidate_num = [0, 0]################was list
        break

if len(candidate_num)>1 and candidate_num[0]==0:
    candidate_num = -1

answer = 0
if not candidate_num==-1:
    if candidate_num[0]==-1:
            candidate_num[0]=1
    
    answer+=candidate_num[0] * 10**(figure-1)

    for i in range(1,figure):
        if candidate_num[i]==-1:
            candidate_num[i]=0

        answer+=candidate_num[i] * 10**(figure-i-1)

    print(answer)

else:
    print(-1)
