n, m = map(int, input().split())
sc = {}
for m2 in range(m):
    sc[m2]=input().split()
dic = {}
num = 0

for li in sc.values():
    if int(li[0]) == 1:
      if n >= 2:
          if int(li[1]) == 0:
              num = -1
              break
    if li[0] in dic.keys():
        if li[1] != dic[li[0]]:
            num = -1
            break
    else:
        dic[li[0]] = li[1]
        num += (10**(n-int(li[0])))*int(li[1])
        
        
        
print(num)