N,M = map(int,input().split())
k = ["N"]*N
flag = 0
count = 0
for i in range(M):
  x,y = map(int,input().split())
  if k[x-1] == "N":
    k[x-1] = y
  elif k[x-1] == y:
    continue
  else:
    print(-1)
    flag += 1
    break
if flag == 0:
  for j in range(10**(N-1),10**N):
    P = str(j)
    for _ in range(N):
      if P[_] == str(k[_]):
        count += 1
        continue
      else:
        if str(k[_]) == "N":
          count += 1
          continue
    if count == N:
      print(j)
      flag += 1
      break
    else:
      count = 0
  if flag == 0:
    print(-1)