#!python3.4.3

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

result = ['a', 'a', 'a']

for _ in range(m):
  s, c = input().split(' ')
  s = int(s) - 1
  
  if result[s] == 'a' or result[s] == c:
    result[s] = c
  else:
    result = '-1'
    break

i = -1 * n

if result != '-1':
  if result[i] == 'a':
    result[i] == 1

  if result != -1:
    result = ''.join(result)
    result = str(int(result.replace('a', '0')))

if len(result) == n and result != -1:
  print(result)
else:
  print(-1)
  
