N, M = map(int, input().split())
SC = [list(map(int,input().split())) for _ in range(M)]
SC = sorted(SC, reverse=True)
min_list =[]
count = 0
for i in range(N):
  min_list.append("0")
for i in range(M):
  if SC[i][0] == 1:
    count += 1
  else:
    pass
if count == 0:
  print(-1)
else:
  for j in range(M):
    min_list[SC[j][0] - 1] = str(SC[j][1])
  answer = "".join(min_list)
  print(int(answer))