N, M = map(int, input().split())
ans = -1
li = []

for i in range(M):
  s, c = map(int, input().split())
  li.append([s, c])
  
for i in range(10**(N-1), 10**N):
  if N==1 and li==[[1, 0]]:
    ans = 0
    break;
  j = 0
  while j < M:
    num = str(i)
    l = li[j]
    if num[l[0]-1] != str(l[1]):
      break;
    j += 1
  else:
    ans = i
    break;
    
print(ans)