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])))

dic = {}
for con in conds:
  if con[0] in dic:
    dic[con[0]].append(con[1])
  else:
    dic[con[0]] = [con[1]]

NUM = [-1] * N

for idic in dic:
  vals = dic[idic]
  vals.sort()
  minVal = vals[0]
  if minVal == 0 and idic == 1:
    try:
       NUM[0] = vals[1]
    except:
       pass
  else:
    NUM[idic-1] = minVal

isOK = True
if NUM[0] == -1 :
  isOK = False
    
for i in range(N):
  if NUM[i] == -1:
    NUM[i] = 0

if isOK == False:
  print(-1)
else:
  strnum = ""
  for i in range(N):
    strnum += str(NUM[i])
    
  print(int(strnum))