import sys

N,M = map(int,input().split())
listA = []
for i in range(M):
   listA.append(list(map(int,input().split())))

# 中身に矛盾がないか
for i in range(len(listA)):
  tmp = listA[i][1]
  for j in range(len(listA)):
    if listA[i][0] == listA[j][0] and listA[i][1] != listA[j][1]:
      print(-1)
      sys.exit()

ansList = [0]*N
for i in range(len(listA)):
	ansList[listA[i][0]-1] = listA[i][1]
ans = ''
for i in range(len(ansList)):
  ans = ans + str(ansList[i])
if str(int(ans)) != ans:
  print(-1)
else:
  print(int(ans))