n, m = map(int, input().split())
S = []
C = []
for i in range(m):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for j in range(m):
  if S[j] == 1 and C[j] == 0:
    print('-1')
    break
  elif S[j] in S:
    l = S.index(S[j])
    if C[l] != C[j]:
      print('-1')
      break
  else:
    continue

h1 = C[S.index(1)]
h2 = 0
h3 = 0
if int(2) in S:
  h2 = C[S.index(2)]

if int(3) in S: 
  h3 = C[S.index(3)]
  
print(100*h1 + 10*h2 + h3)