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

x=0
List=[[A[0][0],A[0][1]]]
for i in range(1,M):
    count=0
    for j in range(len(List)):
        if A[i][0] == List[j][0]:
            count = count+1
            if A[i][1] != List[j][1]:
                x = -1
    if count == 0:
        List.append([A[i][0],A[i][1]])

if x != 0:
    print(-1)
else:
    y = 0
    min = List[0][0]
    ans = 0
    
    for i in range(len(List)):
        if List[i][0] <= min:
            min = List[i][0]
            
    for i in range(len(List)):
        if List[i][1] == 0 and List[i][0] ==1:
            y = -1
    if y!=0:
        print(-1)
    else:
        for i in range(len(List)):
            ans = ans + List[i][1]*(10**(N-List[i][0]))
        if min == 1:
            print(ans)
        else:
            print(ans+10**(N-1))