N, M = [int(x) for x in input().split(" ")]

s = []
c = []
cnt = 0
check = [-1]

for i in range(0,M):
  s.append(" ")
  c.append(" ")
  s[i], c[i] = [int(x) for x in input().split(" ")]
  
for i in range(10**(N-1),10**N):
  cnt = 0
  for j in range(0,M):
    lst = list(str(i))
    if lst[s[j]-1] == str(c[j]):
      cnt +=1
    if cnt == M:
      check.append(i)
      break

if len(check) >= 2:
  print(min(check[1:]))
else:
  print(-1)