import sys

def LI():
  return [int(s) for s in input().split()]

N,M = LI()

check = {}

for i in range(M):
  s,c = LI()
  if N >= 2 and s == 0 and c == 0:
    print(-1)
    sys.exit()
  
  if s in check.keys():
    if check[s] != c:
      print(-1)
      sys.exit()
      
  check[s] = c

answer = ['0']*N
answer[0] = '1'

for s,c in check.items():
  answer[s-1] = str(c)
  
print(int(''.join(answer)))