# input
N, M = map( int, input().split() )
S = [-1]*M
C = [-1]*M
for mm in range( M ):
    S[mm], C[mm] = map( int, input().split() )
     
ans = -1
if( M <= N ):
    check = True
    ans_s = ["0"]*N
    for mm in range( M ):
        idx = S[mm]-1
        if( len(ans_s) < idx ):
            check = False
            continue
        ans_s[idx] = str(C[mm])
        
        
    if( check and ans_s[0] != "0" ):
        ans = int( "".join(ans_s) )

print( ans )