package main

import (
	"fmt"
  "math"
  //"sort"
	//"strconv"
)
func pow(p, q int) int {
    return int(math.Pow(float64(p), float64(q)))
}
func main() {
  var N,M int
  fmt.Scanf("%d %d",&N,&M);
  s := make([]int, M)
  c := make([]int, M)


  m := map[int]int{}

  for i:=0; i<M; i++{
    fmt.Scanf("%d %d",&s[i],&c[i]);
    if m[s[i]]==0{
      m[s[i]]=c[i]
    }else{
      if m[s[i]]!=c[i]{
        fmt.Print("-1")
        return
      }
    }
  }

  var ans int
  for key, value := range m{
    if key==1{
      ans+=value*pow(10,N-1)
    }else if key==2{
      ans+=value*pow(10,N-2)
    }else{
      ans+=value*pow(10,N-3)
    }
  }



  fmt.Print(ans)

}