fun main(args: Array<String>) {
  var range: String? = readLine()
  var param = range!!.split(" ")
  var height: Int = param[0].toInt()
  var width: Int = param[1].toInt()
  var row : String? = ""
  var check = '.'
  var count = Array<Int>(width,{height + width})
  var last = 0
  var oldRow = ""
  for(i in 0 until width){
    oldRow += '.'
  }
  for(i in 0 until height){
    row = readLine()
    for(j in 0 until width){
      if(row!![j] == '#'){
        if(oldRow[j] == '.' ){
          count[j]++
        }
        if(check == '.'){
          last++
        }
      }
      if(last < count[j]){
        count[j] = last
      }
      last = count[j]
      check = row!![j]
    }
    last = height + width
    check = '.'
    oldRow = row!!
  }
  println(count[count.lastIndex].toString())
}