n,m = map(int, input().split())

p = [0]*n
q = [False]*n
for i in range(m):
  s,c = map(int, input().split())
  if s == 1 and c == 0:
    continue
  if q[s-1] == False:
    p[s-1] = c
    q[s-1] = True
  elif p[s-1] > c:
    p[s-1] = c

t = ''
for i in p:
  t += str(i)
  
t = int(t)
if len(str(t)) == n:
  print(str(t))
else:
  print('-1')