N,M = map(int, input().split())
candidate = [-1]*N
flag = False
for i in range(M):
  s_temp,c_temp = map(int, input().split())
  if candidate[s_temp-1] == -1:
    candidate[s_temp-1] = c_temp
  elif candidate[s_temp-1] == c_temp:
    pass
  else:
    flag = True
    break
if flag == True or (candidate[0] == 0 and N != 1):
  print(-1)
else:
  if candidate[0] == -1:
    candidate[0] = 1
  output_list = [0 if i == -1 else i for i in candidate]
  print(int(''.join(map(str, output_list))))