

fun search(state: Array<BooleanArray>, memo: Array<IntArray>, position:Int = 0, prev: Int = 0): Int{
    if (state.size - position <= 1) return 0
    if (memo[position][prev] >= 0) return memo[position][prev]
    val coord = (0..1).flatMap{i -> (0..1).map{j -> Pair(i, j)}}
    if ((prev and 1) != 0 || prev == 4) {
        state[position][1] = false
    }
    if ((prev and 2) != 0 || prev == 4){
        state[position][2] = false
    }
    if (coord.all{state[position + it.first][it.second]} || coord.all{state[position + it.first][it.second + 2]}) {
        val current = (if (coord.all{state[position + it.first][it.second]}) 1 else 0) + (if (coord.all{state[position + it.first][it.second + 2]}) 2 else 0)
        memo[position][prev] = search(state, memo, position + 1, current) + if (current == 3) 2 else 1
    } else if (coord.all{state[position + it.first][it.second + 1]}){
        memo[position][prev] = maxOf(search(state, memo, position + 1, 4) + 1, search(state, memo, position + 1, 0))
    }else {
        memo[position][prev] = search(state, memo, position + 1, 0)
    }
    if ((prev and 1) != 0 || prev == 4) {
        state[position][1] = true
    }
    if ((prev and 2) != 0 || prev == 4){
        state[position][2] = true
    }
    return memo[position][prev]
}
fun main(args:Array<String>): Unit {
    val (h, n) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(h){BooleanArray(4){true}}
    val memo = Array(h){IntArray(5){-1}}
    repeat(n){
        val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        state[y][x] = false
    }
    for (i in h downTo 0 step 100) search(state, memo, i)
    println(search(state, memo))
}
