N, M = map(int,input().split())

sc = {}
f = True
for i in range(M):
  s, c = map(int,input().split())
  if N > 1 and s == 1 and c == 0:
    print(-1)
    f = False
    break
  if s not in sc:
    sc[s] = c
  else:
    if sc[s] == c:
      continue
    else:
      print(-1)
      f = False
      break

if f:
  s = ''
  for i in range(1,N+1):
    if i in sc:
      s += str(sc[i])
    else:
      s += str(0)
  print(s)
