N,M=map(int,input().split())
First = 10**N-1
Answer =0
An = {}
box = []
for m in range(M):
    box.append(list(map(int,input().split())))
for m in range(M):
    if box[m][0] not in An:
        if box[m][0]  == 1 and box[m][1] == 0:
            Answer =-1
            break
        An[box[m][0]] = box[m][1]
    else:
        if An[box[m][0]] != box[m][1]:
            Answer =-1
            break
if 1 not in An and 2 in An:
    if An[2] == 0:
        Answer = -1
if 2 not in An and 3 not in An:
    if Answer !=-1:
        if 1 in An:
            Answer =An[1]
else:
    if 3 not in An:
        if Answer != -1:
            if 1 not in An:
                if 2 in An:
                    Answer = An[2]
                else:
                    Answer =-1
            else:
                An.setdefault(2,0)
                Answer = 10*An[1] + 1*An[2]
    else:
        if N ==3:
            if Answer != -1:
                if 1 not in An:
                    if 2 not in An:
                        if 3 in An:
                            Answer = An[3]
                        else:
                            Answer = -1
                    else:
                        An.setdefault(3,0)
                        Answer = 10*An[2] + An[3]
                else:
                    An.setdefault(3,0)
                    An.setdefault(2,0)
                    Answer = 100*An[1] + 10*An[2] + An[3]
print(Answer)