import sys
lines = sys.stdin.readlines()
line1 = lines.pop(0).split(' ')
#print(line1)
N = int(line1[0])
M = int(line1[1])

#print(N)
#print(M)

str = [0] * N
ans = []
flg = 0
for i in range(M):
  line = lines.pop(0).split(' ')
#  print(line)
  s = int(line[0])
  c = int(line[1])
#  print(s)
#  print(c)
  str[s-1] = c
#  print('str = ')
#  print(str)
  one = int(str[0])
  if N == 3:
    ret = one*100 + int(str[1])*10 + int(str[2])
    if int(str[1])>0 or int(str[2])>0:
      flg = 1
  elif N == 2:
    ret = one*10 + int(str[1])
    if int(str[1]) > 0:
      flg = 1
  else:
    if one > 0:
      ret = one
  ans.append(ret)

#print(ans)
div = 1
if N == 3:
  div = 100
elif N == 2:
  div = 10

for obj in ans[:]:
  if (obj / (10**(N-1))) < 1:
    ans.remove(obj)
  elif flg == 1:
#   print('リムーブ候補')
#   print(obj)
#   print(div)
    a = obj % div
    print(a)
    if a == 0:
#      print('リムーブ')
      ans.remove(obj)

if not ans:
  print('-1')
else:
#  print(ans)
  print(min(ans))
