N,M=map(int, input().split())
SC=list(list(map(int, input().split())) for i in range(M))

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
sc=get_unique_list(SC)

if (N==3) & (max(sc)[0]!=3):
    sc.append([1,1])
if (N==2) & (max(sc)[0]!=2):
    sc.append([2,1])

res=0
if M==0:
    res=-1
for i in range(len(sc)):
    for j in range(len(sc)):
        if (i!=j) & (sc[i][0]==sc[j][0]):
            res=-1
            break
    break
for i in range(len(sc)):
    if (M!=1) & (sc[i][0]==1) & (sc[j][1]==0):
        res=-1
        break
if N<len(sc):
    res=-1
if res!=-1:
    for i in range(len(sc)):
        res = res + sc[i][1]*(10**(N-sc[i][0]))
print(res)