N, M = map(int, input().split())
if M == 0:
  if N == 1:
    print(0)
  else:
    m = 10 ** (N - 1)
    print(m)
else:
  dic = {}
  t = ''
  flg = True
  flg2 = True
  for _ in range(M):
    s, c = map(int, input().split())
    if s not in dic:
      dic[s] = c
    else:
      flg = False
      break
  if flg:
    if N == 1:
      if dic[1] == 0:
        print(0)
      else:
        print(dic[1])
    else:
      if 1 in dic:
        if dic[1] == 0:
          flg2 = False
        else:
          t += str(dic[1])
      for j in range(2, N + 1):
        if j in dic:
          t += str(dic[j])
        else:
          t += '0'
    if flg2:
      print(int(t))
    else:
      print(-1)
  else:
    print(-1)

