n,m=map(int,input().split())
k=[]
s=-1
ans=0
l=0
if m==0 and n==1:
  print(l)
  l+=1
if l==0:
  for i in range(m):
    c=list(map(int,input().split()))
    k.append(c)
k=sorted(k,key=lambda x:x[0])
if [1,0] in k and n!=1:
  print(s)
  l+=1
if l==0:
  for i in range(m-1):
    if k[0]!=k[1]:
      if k[0][0]==k[1][0]:
        print(s)
        l+=1
        break
      else:
        ans+=k[0][1]*(10**(3-k[0][0]))
        k.remove(k[0])
    else:
      k.remove(k[0])
if l==0:
  ans+=k[0][1]*(10**(3-k[0][0]))
  print(ans)