line = input().split()
N, M = int(line[0]), int(line[1]) 

conds = []
for i in range(M):
  line = input().split()
  conds.append((int(line[0]),int(line[1])))

NUM = [-1] * N

isOK = True
for curCon in conds:
  s = curCon[0]
  dig = curCon[1]
  
  if s != 1:
    if NUM[s-1] == -1:
      NUM[s-1] = dig
    elif NUM[s-1] > dig:
      NUM[s-1] = dig
  else:
    if NUM[0] == -1 and dig > 0:
      NUM[0] = dig
    elif NUM[0] > dig and dig > 0:
      NUM[0] = dig
      
if N > 1:
  if NUM[0] == -1 or NUM[0] == 0:
    isOK = False

if isOK != True:
  print(-1)
else:
  for i in range(N):
    if NUM[i] == -1:
      NUM[i] = 0
  numChar = ""
  for iNum in NUM:
    numChar += str(iNum)
  print(int(numChar))