N,M=map(int,input().split())
First = 10**N-1
box = []
for j in range(M):
    box.append(list(map(int,input().split())))
def f(x):
    if x >=100:
        return str(x)
    elif x>=10:
        return '0'+str(x)
    else:
        return'0'+'0'+str(x)
Answer = -1
for i in range(First):
    if Answer != -1:
        break
    Aqu = f(First - i)
    for m in range(M):
        if Aqu[box[m][0]-1] != str(box[m][1]):
            break
        elif m == M-1:
            Answer = Aqu
            break
for m in range(M):
    if box[m] == [1,0] and Answer =='099':
        Answer = -1
    elif box[m] == [2,0] and Answer =='009':
        Answer = -1
if Answer != -1:
    if Answer[0] =='0':
        if Answer [1] =='0':
            print(Answer[2])
        else:
            print(Answer[1]+Answer[2])
    else:
        print(Answer)
else:
    print(Answer)