fun main() {
  val cmp = compareBy<Pair<Int, Int>> { it.first }.thenBy { it.second }
  val mx = sortedSetOf<Pair<Int, Int>>(cmp)
  val my = sortedSetOf<Pair<Int, Int>>(cmp)
  val (n, q) = readLine()!!.split(" ").map { it.toInt() }
  var m = (n - 2L) * (n - 2L)
  repeat(q) {
    val (t, x) = readLine()!!.split(" ").map { it.toInt() }
    val p = if (t == 1) my.higher(x to 0) else mx.higher(x to 0)
    val h = p?.let { it.second } ?: n
    m -= h - 2
    if (t == 1) mx.add(h to x) else my.add(h to x)
  }
  println(m)
}