n,m = input().split(" ")
n = int(n)
m = int(m)
ans = -1
ans1 = ['0']*n
for i in range(m):
    si, ci = input().split(" ")
    si=int(si)
    if(ans1[si-1]=='0'):
        ans1[si-1]=ci
    elif(ans1[si-1]>ci):
        ans1[si-1]=ci
        
if(int(('').join(ans1))==0 and n==1):
    ans=0        
elif(ans1[0]!='0'):
    ans = int(('').join(ans1))

print(ans)    