n,m= map(int,input().split(' '))
num = {}
keta = [100,10,1]
for i in range(m):
  s,c = map(int,input().split(' '))
  s = keta[s-1]
  if ((s in num) and num[s]!=c):
    print('-1')
    exit(0)
  elif (s==100 and c==0):
    continue
  else:
    num[s] = c
    
number = 0
for d in num:
  number+=d*int(num[d])
print(number)