# -*- coding:utf-8 -*-
n, m = map(int, input().strip().split())
digit = {}
f_one = False
for i in range(m):
    tmp_d, tmp = map(int, input().strip().split())
    if tmp_d == 1:
      f_one = True
      
    if ((tmp_d == 1) and (tmp == 0)):
        print(-1)
        exit()
    elif (tmp_d in digit.keys()) and (digit[tmp_d] != tmp):
        print(-1)
        exit()
    else:
        digit[tmp_d] = tmp

if not f_one:
	digit[1] = 1
    
ans = 0
for key in digit.keys():
    ans += digit[key]*(10**(n-key))
if ans != 0:
  print(ans)
else:
  print(-1)