N, M = map(int, input().split())
leftNum = {}
intList = []
mark = 0 

for i in range(M):
  fromLeft, num = map(int, input().split())
  if fromLeft in leftNum and num != leftNum[fromLeft]:
    mark = 1
  else:
    leftNum[fromLeft] = num

for key in range(1, M + 1):
  #print(key)
  if key in leftNum:
    intList.append(str(leftNum[key]))
  else:
    intList.append('0')

stringNum = ''.join(intList)
if not stringNum == "":
  intNum = int(stringNum)

#print(leftNum)
#print(intList)

# not(intList[0] == 0 and N > 1) -> leading zero
if len(intList) == N and (intList[0] != '0' and N > 1):
  print(intNum)
else:
  mark = 1

if mark == 1:
  print(-1)