n,m = map(int,input().split())
dic = {}
sum = 0
for i in range(m):
  s,c = map(int,input().split())
  if s in dic and dic[s] != c:
    print(-1)
    break
  dic[s] = c
else:
  if 1 in dic and dic[1] == 0:
    print(-1)
  elif 1 not in dic:
    dic[1] = 1
    for i in dic:
      sum += dic[i]*((10)**(n-i))
    print(sum)
  else:
    for i in dic:
      sum += dic[i]*((10)**(n-i))
    print(sum)
