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

digit = [10] * 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] != c_new and digit[s_new - 1] != 10:
    ans = -1
    break
  else:
    digit[s_new - 1] = c_new


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