import sys
N,M = map(int,input().split())
conditionDict={} #appendのために宣言が必要
endFlag = 0
for i in range(M):
  tmpMap = list(map(int,input().split()))
  if not(tmpMap[0] in conditionDict):
  	conditionDict[tmpMap[0]] = tmpMap[1]
  else:
    if tmpMap[1] != conditionDict[tmpMap[0]]:
      print(-1)
      sys.exit()

ansList = [0]*3
for key in conditionDict.keys():
  ansList[3-key] = conditionDict[key]

ans = int(str(ansList[2])+str(ansList[1])+str(ansList[0]))
if len(str(ans))!=N:
	print(-1)
else:
  print(ans)
