N, M = list(map(int, input().split()))
nums = [list(map(int, input().split())) for i in range(M)]
if [1, 0] in nums:
  print('-1')
  quit()
dic = {}

for (s, c) in nums:
  if s in dic and dic[s] != c:
    print('-1')
    quit()
  else:
    dic[s] = c

total = 10**(N-1)    
for key in sorted(dic.keys()):
    if key == 1:
   		total = 10**(N-key)*dic[key]
    else:
        total += 10**(N-key)*dic[key]
print(total)