N, M = map(int, input().split())
s = list()
c = list()
for i in range(M):
  s1, c1 = map(int, input().split())
  s.append(s1)
  c.append(c1)

flag = 0
j = 0
while(flag == 0 and j < 1000):
  flag = 1
  A = str(j)
  for i in range(M):
    if(len(A) != N):
      flag = 0
      break
    elif(len(A) < int(s[i])):
      flag = 0
      break
    elif(int(A[s[i]-1]) != int(c[i])):
      flag = 0
      break
  j += 1

if(M == 0):
  print("0")
elif(flag == 1):
  print(j-1)
else:
  print("-1")
  
