N,M = map(int,input().split())
flag = 0
num = ["F"]*N
for i in range(M):
  s,c = map(int,input().split())
  if num[s-1] == "F":
    num[s-1] = str(c)
    continue
  elif num[s-1] == str(c):
    continue
  else:
    flag += 1
    break
if flag == 1:
  print(-1)
else:
  ans = ""
  ans_2 = ""
  flag_2 = 0
  for i in range(N):
    if num[i] == "F":
      ans += "0"
    else:
      ans += num[i]
  for i in range(N):
    if ans[i] == "0":
      if flag_2 == 0:
        continue
      else:
        ans_2 += "0"
    else:
      ans_2 += ans[i]
      flag_2 += 1
  if len(ans_2) == 0:
    print(-1)
  else:
    print(ans_2)