op = [list(map(int, inp.split())) for inp in open(0)]
n = op[0][0]
m = op[0][1]
s = []
c = []
dict_ = {}
flag = True
for i in range(1, m + 1):
  s = n + 1 - op[i][0]
  c = op[i][1]
  if s in dict_:
    if dict_[s] == c:
      pass
    else:
      flag = False
  else:
    dict_[s] = c
  if s == n and c == 0:
    flag = False
if n in dict_:
  res = 10 ** (n - 1) * dict_[n]
else:
  res = 10 ** (n - 1)
for i in range(n - 1):
  if i + 1 in dict_:
    res += 10 ** i * dict_[i + 1]
if flag:
  print(res)
else:
  print(-1)