N, M = map(int, input().split())
num = ['']*N
valid = True
#create number from input
for i in range(M):
  s, c = map(int, input().split())
  if ((num[s-1] == c) or (num[s-1] == '')):
    num[s-1] = c
  else:
    valid = False
    break
#check whether 0 is at front
if (num[0]==0):
  valid = False
  
if valid:
  first = True
  #fill the blank parts
  for i in range(N):
    if ((first) and (num[i] == '')):
      num[i] = 1
    elif ((not first) and (num[i] == '')):
      num[i] = 0
    first = False
  #convert list to number
  answer = 0
  for i in range(N):
    answer *= 10
    answer += num[i]
  print(answer)
else:
  print(-1)