i = input().split(" ")
n = int(i[0])
m = int(i[1])
sc = []

for i in range(m):
  p = input().split(" ")
  p =  [int(j) for j in p]
  sc.append(p)

rs = []
rn_flg = []
fuseiflg = 0
for i in range(n):
  rs.append(0)
  rn_flg.append(0)

for i in sc:
  if rn_flg[i[0] - 1] == 0:
    rs[i[0] - 1] = i[1]
    rn_flg[i[0] - 1] = 1
  else:
    if rs[i[0] - 1] == i[1]:
      pass
    else:
      fuseiflg = 1

#print(rs)
#print(rn_flg)
#print(fuseiflg)
#print(rn_flg.index(1))

if(1 in rn_flg):
  if rn_flg.index(1) > 0:
    rs[0] = 1
    tmp = [str(j) for j in rs]
    res = "".join(tmp)
    res = int(res)
  else:
    if rs[0] == 0:
      fuseiflg = 1
    else:
      tmp = [str(j) for j in rs]
      res = "".join(tmp)
      res = int(res)
else:
  res = 10 ** (n - 1)

if fuseiflg == 1:
  print(-1)
else:
  print(res)