n, m = map(int, input().split())

S = []
C = []
for i in range(m):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)

if n == 1:
  start_num = 1
  end_num = 10
if n == 2:
  start_num = 10
  end_num = 100
if n == 3:
  start_num = 100
  end_num = 1000
  
for num in range(start_num, end_num):
  for i in range(m):
    if str(num)[S[i] - 1] != str(C[i]):
      break
  else:
    print(num)
    break
else:
  print(-1)