object Main extends App {
  import scala.io.StdIn._

  object Pasta {
    val pastas: List[Pasta] = List(Tomato, Cream, Basil)
  }
  sealed class Pasta(val toIndex:Int)
  case object Tomato extends Pasta(0)
  case object Cream extends Pasta(1)
  case object Basil extends Pasta(2)
  val mod = 10000

  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val pasta = Array.tabulate(n){_ ⇒ None: Option[Pasta]}.also{arr ⇒
    for (_ ← 0 until k){
      val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
      arr(a - 1) = Some(b match {
        case 1 ⇒ Tomato
        case 2 ⇒ Cream
        case 3 ⇒ Basil
      })
    }
  }.toList
  println(
    calPatternExcept(pasta)
  )
  def calPatternExcept(plan: List[Option[Pasta]], notAllow: Option[Pasta] = None, length: Int = 0)(implicit memo:Array[Array[Option[Int]]] = Array.tabulate(plan.length){_ => Array.tabulate(3){_ => None: Option[Int]}}): Int = {
    if (length > memo.length) 0
    else if (length == memo.length) 1
    else {
      notAllow match {
        case None ⇒ (plan match {
          case Nil ⇒ 1
          case None::None::t ⇒ Pasta.pastas.map(p ⇒ calPatternExcept(None::t, Some(p), length + 1) + calPatternExcept(t, Some(p), length + 2)).sum
          case None::Some(n)::t ⇒ Pasta.pastas.map{
            case `n` ⇒ calPatternExcept(t, Some(n), length + 2)
            case p ⇒ calPatternExcept(Some(n)::t, Some(p), length + 1)
          }.sum
          case Some(a)::None::t ⇒ calPatternExcept(None::t, Some(a), length + 1) + calPatternExcept(t, Some(a), length + 2)
          case Some(a)::Some(b)::t if a == b ⇒ calPatternExcept(t, Some(a), length + 2)
          case Some(a)::Some(b)::t ⇒ calPatternExcept(Some(b)::t, Some(a), length + 1)
          case None::Nil ⇒ 3
          case Some(_)::Nil ⇒ 1
        }).let(_ % mod)
        case Some(n) if memo(length)(n.toIndex).isDefined ⇒ memo(length)(n.toIndex).get
        case Some(n) ⇒ (plan match {
          case Nil ⇒ 1
          case Some(a)::_ if a == n ⇒ 0
          case None::None::t ⇒ Pasta.pastas.filterNot(_ == n).map(p ⇒ calPatternExcept(None::t, Some(p), length + 1) + calPatternExcept(t, Some(p), length + 2)).sum
          case None::Some(a)::t ⇒ Pasta.pastas.filterNot(_ == n).map{
            case `a` ⇒ calPatternExcept(t, Some(a), length + 2)
            case p ⇒ calPatternExcept(Some(a)::t, Some(p), length + 1)
          }.sum
          case Some(a)::None::t ⇒ calPatternExcept(None::t, Some(a), length + 1) + calPatternExcept(t, Some(a), length + 2)
          case Some(a)::Some(b)::t if a == b ⇒ calPatternExcept(t, Some(a), length + 2)
          case Some(a)::Some(b)::t ⇒ calPatternExcept(Some(b)::t, Some(a), length + 1)
          case None:: Nil ⇒ 2
          case Some(_)::Nil ⇒ 1
        }).let(_ % mod).also(i ⇒ memo(length)(n.toIndex) = Some(i))
      }
    }
  }
  implicit class ScopeFunc[T](value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
