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

for i in range(M):
  s, c = map(int, input().split())
  if not [s, c] == [1, 0]:
    li.append([s, c])
  
if N==1 and li==[]:
  ans = 0
else:
  for i in range(10**(N-1), 10**N):
    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)
