n,m = map(int, input().split())
SC = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
  if SC[i][0] == 1 and SC[i][1] == 0:
    print(-1)
    exit()
  else:
    pass
  
  for j in range(0,m):
    if (SC[i][0] == SC[j][0]) and (SC[i][1] != SC[j][1]):
      print(-1)
      exit()
    else:
      pass

ANS = [SC[0]]
for i in range(m):
  if SC[i] not in ANS:
    ANS.append(SC[i])
  else:
    pass
ANS.sort()
ans = [0] * n
for i in range(len(ANS)):
  if ANS[i][1] != 0:
    ans[ANS[i][0]-1] = ANS[i][1]
  else:
    pass
if ans[0] == 0:
  ans[0] = 1
  print("".join([str(ans[i]) for i in range(len(ans))]))
else:
  print("".join([str(ans[i]) for i in range(len(ans))]))