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)

res=0
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 (sc[i][0]==1) & (sc[j][1]==0):
        res=-1
        break
if res!=-1:
    for i in range(len(sc)):
        res = res + sc[i][1]*10**(M-sc[i][0])
print(res)