n,m = map(int, input().split())

p = ['0']*n
for i in range(m):
  s,c = input().split()
  s = int(s)
  p[s-1] = c

t = 0
for i in p:
  t += int(i)

if len(str(t)) == n:
  print(int(t))
else:
  print(-1)