n, m =map(int,input().split())
s = []
c = []
for _ in range(m):
  S, C =map(int,input().split())
  s.append(S)
  c.append(C)
for i in range(10**(n-1),(10**n)+1):
  l = str(i)
  if all( [ l[s[j]-1] == str(c[j]) for j in range(m)]):
    print(i)
    break
else:
  print("-1")