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]*N
for key in conditionDict.keys():
  ansList[N-key] = conditionDict[key]
ans = ''
for i,ansElement in enumerate(ansList):
  ans = ans + str(ansElement)
ans = int(ans)
if len(str(ans))!=N:
  print(-1)
else:
  print(ans)