N,M = list(map(int,input().split()))
from collections import defaultdict
q = defaultdict(set)
for i in range(M):
  s,c = list(map(int,input().split()))
  q[s] |= {c}

for i in range(10**N):
  for key,value in q.items():
    v = list(value)[0]
    if len(value)>1:
      break
    elif len(str(i)) < key or str(i)[key-1] != str(v):
      break
  else:
    print(i)
    break
else:
  print(-1)