keta,num=map(int,input().split())
list=[list(map(int,input().split())) for i in range(num)]

ans = [0]*keta
for i in range(num):
  if ans[list[i][0]-1] < list[i][1]:
    ans[list[i][0]-1] = list[i][1]
if ans[0] == 0:
  if keta == 1:
    print(0)
  elif ans.count(0) == keta:
    print(0)
  else:
    print(-1)
else:
  a = ''
  for s in ans:
    a += str(s)
  print(a)