fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val t = (1..h).map { readLine()!! }
    val dp = Array(h + 1) { Array(w + 1) { Array(2) { Int.MAX_VALUE } } }

    dp[0][0][0] = 0
    dp[0][0][1] = 1

    for (i in 0 until h) {
        for (j in 0 until w) {
            for (use in 0..1) {
                if (dp[i][j][use] == Int.MAX_VALUE) continue
                val nextUse =
                        if (t[i][j] == '#' && use == 0) {
                            1
                        } else if (t[i][j] == '.' && use == 1) {
                            0
                        } else {
                            use
                        }
                val addCost = if (use == 0 && nextUse == 1) 1 else 0
                dp[i + 1][j][nextUse] = Math.min(dp[i + 1][j][nextUse], dp[i][j][use] + addCost)
                dp[i][j + 1][nextUse] = Math.min(dp[i][j + 1][nextUse], dp[i][j][use] + addCost)
            }
        }
    }
    var ans = dp[h][w - 1][0]
    ans = Math.min(ans, dp[h][w - 1][1])
    ans = Math.min(ans, dp[h - 1][w][0])
    ans = Math.min(ans, dp[h - 1][w][1])
    println(ans)
}
