N, M = map(int, input().split(' '))

s_old = []
s_c_old =[]
result = 0
FLAGS = True
for i in range(M):
  s, c = map(int, input().split(' '))

  if (s == 1) & (c == 0):
    print('-1')
    FLAGS = False
    break
  elif (s in s_old):
    if ([s,c] in s_c_old):
      s_old.append(s)
      s_c_old.append([s,c])
    else:
      print('-1')
      FLAGS = False
      break
  else:
    result += c*10**(N - s)
    s_old.append(s)
    s_c_old.append([s,c])

if (N == 1) and (M == 0):
  result = 0
elif 1 in s_old:
  result = result
else:
  result += 1*10**(N - 1)
  
if FLAGS == True:
  print(result)
