n,m = map(int,input().split())
li = []
itg = 0
flag = True
for _ in range(m):
  li.append(list(map(int,input().split())))
li = sorted(li, key = lambda x:x[0], reverse=True)
for i in range(m-1):
  if li[i][0] == li[i+1][0]:
    if li[i][1] != li[i+1][1]:
      print(-1)
      flag = False
    else:
      li[i][1] = 0
if flag:
  k = li[0][0]
  for l in li:
    itg += l[1] * (10 ** (k-l[0]))
  print(itg)