N, M = input().split(" ")

data = 0

double_check_s = []
double_check_c = []
ng_flag = 0

for i in range(0, int(M)):
  
  s, c = input().split(" ")
  
  if s == "1" and c == "0":
    ng_flag += 1
  elif s in double_check_s:
    if c == double_check_c[double_check_s.index(s)]:
      pass
    else:
      ng_flag += 1
  else:
    data += 10 ** (int(N) - int(s)) * int(c)
  
  double_check_s.append(s)
  double_check_c.append(c)
  # print(double_check_s)
  # print(double_check_c)
  
if ng_flag != 0:
  print(-1)
elif data // 10 ** (int(N) - 1) == 0:
  print(data + 10 ** (int(N) - 1))
else:
  print(data)