n,m=map(int, input().split())
box = ["0" for i in range(n)]
S=[]
C = []
s,c=map(str, input().split())
S.append(s)
C.append(c)
for i in range(m-1):
    s,c=map(str, input().split())
    
    if s in S:
        if int(c) <= int(C[S.index(s)]):
            del C[S.index(s)]
            del S[S.index(s)]
            S.append(s)
            C.append(c)
            
for i in range(len(S)):
    box[int(S[i]) -1] = (C[i]) 
            
        
        
if n > 1 and box[0] == '0':
    print(-1)
    
else:
    for x in box:
        ans += x
    print(x)
    
    
    
