# -*- coding:utf-8 -*-
n, m = map(int, input().strip().split())
ans = 0
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)):
        ans = -1
        break
    elif (tmp_d in digit.keys()) and (digit[tmp_d] != tmp):
        ans = -1
        break
    else:
        ans += tmp*(10**(n-tmp_d))
      
if not f_one:
	ans += 1*(10**(n-1))
  
print(ans)