import sys

ar = []
x = sys.stdin.readline()
x = x.split(' ')
(n,m)=[int(str) for str in x]

ret = 0
chk = []
for i in range(m):
  x = sys.stdin.readline()
  x = x.split(' ')
  (s,c)=[int(str) for str in x]
  if not ( s in chk):
    if(n-s>=0):
      ret += c*10**(n-s)
      chk.append(s)
  else:
    if( c != int(ret/10**(n-s))):
      print("-1")
      exit(0)

if( ret == 0 and n == 1):
  print("0")
  exit(0)
if( ret < 10**(n-1)):
  if not ( n-1 in chk):
    print(ret+10**(n-1))
  else:
    print("-1")
else:
  print(ret)
sys.stdout.flush()
