fun main(args: Array<String>?): Unit {
    val (m, _) = readLine()!!.trim().split(' ').map(String::toInt)
    val chocolate = Array(m){ readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
    chocolate.forEach {
        it[0] = (it.first() + 1) % 2
        it[it.lastIndex] = (it.last() + 1) % 2
    }
    chocolate[0].indices.forEach { chocolate[0][it] = (chocolate[0][it] + 1) % 2 }
    println(
            chocolate.sumBy { if (it.any{it == 0}) it.count { it == 1 } + 1 else it.size - 1 }
    )
}
