import sys

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:
        print(-1)
        sys.exit()

if len(candidate_num)>1 and candidate_num[0]==0:
    print(-1)
    sys.exit()

answer = 0
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)
