import re
n , m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
#n,m = 3,1
#sc = [[3,1]]

ck = True
a = ['a'] * (n+1)
for s,c in sc :

  if a[s] == 'a' :
    a[s] = str(c)
  else :
    if a[s] != str(c) :
      ck = False
      break

  if n >= 2 and s == 1 and c == 0 :
    ck = False
    break

if a[1] == 'a':
  a[1] = '1'

b = ''.join(a[1:])
b = re.sub('a','0',b)

if ck :
  print(int(b))
else :
  print('-1')