import sys
N,M=map(int, input().split())
num_list = []
for i in range(M):
    num_list.append(list(map(int,input().split())))

if M==0:
    print('-1')
    sys.exit()

x=0
while x<=M-2:
    y=x+1
    while y<=M-1:
        if num_list[x]==num_list[y]:
            del(num_list[y])
            M=M-1
        else:
            y=y+1
            continue
    x=x+1

list1=[]
list2=[]
s=0
t=0
while s<=M-1:
    list1.append(num_list[s][0])
    s=s+1

while t<=M-1:
    list2.append(num_list[t][1])
    t=t+1

def has_duplicates(seq):
    return len(seq) != len(set(seq))

z=0
if has_duplicates(list1)==1:
    print('-1')
elif N>=2 and list2[0]==0:
    print('-1')
elif N==1 and list2[0]==0:
    print('0')
else:
    p=0
    while p<M:
        z=z+list2[p]*10**(N-list1[p])
        p=p+1

    if N==3 and z<100:
        z=z+100
        print(z)
    elif N==2 and z<10:
        z=z+10
        print(z)
    else:
        print(z)
