import sys
n, m = map(int, input().split())
S,C=[],[]
if m == 0:
  print(-1)
  sys.exit()
for _ in range(m):
  s,c=map(int,input().split())
  S.append(s)
  C.append(c)
cur = 0
for i in range(10**(n-1), 10**n):
  isOk = True
  for j in range(m):
    if str(i)[S[j]-1] != str(C[j]):
      isOk = False
  if isOk:
    print(i)
    sys.exit()
print(-1)