string = input().split(' ')
N = int(string[0])
M = int(string[1])

digit = [0] * N
ans = 0

for i in range(M):
  string = input().split(' ')
  s_new = int(string[0])
  c_new = int(string[1])
  if digit[s_new - 1] != 0 and digit[s_new - 1] != c_new:
    ans = -1
    break
  else:
    digit[s_new - 1] = c_new
print(digit)

if ans == -1 or digit[0] == 0:
  print('-1')
else:
  for i in range(N):
    ans = ans + digit[i] * ( 10 ** (N - i -1))
   
  print(ans)
  