N,M = map(int,input().split())
List=[list(map(int,input().split())) for i in range(M)]

def imp(n, m, lst):
  for i in range(m):
    if (lst[i][0] == 1) and (lst[i][1] == 0):
      return True
  for i in range(0, m-1):
    for j in range(1, m):
      if (lst[i][0] == lst[j][0]) and (lst[i][1] != lst[j][1]):
        return True
  return False

def num(n, m, lst):
  if imp(n, m, lst):
    return -1
  res = []
  for i in range(n):
    res.append(0)
  for i in range(m):
    res[lst[i][0]-1] = lst[i][1]
  if res[0] == 0:
    res[0] = 1
  return("".join(map(str, res)))

print(num(N,M,List))