import sys

n,m = map(int,input().split())
sc = []

for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if n == 1:
  print(sc[0][1])
  sys.exit()
if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

num = 0
while len(sc) > num+1:
  if sc[num][0] == sc[num+1][0]:
    if sc[num][1] == sc[num+1][1]:
      del sc[num]
      num = 0
      continue
    else:
      print('-1')
      sys.exit()
  num += 1

ans = [0 for _ in range(n)]
for i in range(len(sc)):
  ans[sc[i][0]-1] = sc[i][1]
if ans[0] == 0:
  ans[0] = 1

res = ''
for i in range(len(ans)):
  res = res + str(ans[i])

print(res)
