import sys
import math
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
flg2 = 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:
      flg = 1
    if str[s-1] == str[1] and c == 0:
      flg = 2

    if int(str[2])>0:
      flg2 = 1
    if str[s-1] == str[2] and c == 0:
      flg2 = 2
  elif N == 2:
    ret = one*10 + int(str[1])
    if int(str[1]) > 0:
      flg = 1
    if str[s-1] == str[1] and c == 0:
      flg = 2

  else:
    ret = one
  ans.append(ret)

#print(ans)

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

  elif N == 3:
    if flg == 1 and flg2 ==1:
#      print('リムーブ候補')
#      print(obj)
      if obj % 100 == 0:
#        print('リムーブ')
        ans.remove(obj)
      elif obj > 10 and math.floor(obj/10) % 10 == 0:
#        print('リムーブ')
        ans.remove(obj)
      elif obj % 10 == 0:
#        print('リムーブ')
        ans.remove(obj)
    elif flg == 1 and flg2 ==0:
      if obj % 100 == 0:
        ans.remove(obj)
    elif flg == 0 and flg2 ==1:
#      print('リムーブ候補')
#      print(obj)
      b = obj % 10
#      print(b)
      if b == 0:
#        print('リムーブ')
        ans.remove(obj)

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