/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int m, n;
    cin >> m>> n;
    int a[m][n];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            char temp;
            cin >> temp;
            if(temp == '.'){
                a[i][j] = 0;
            }
            else{
                a[i][j] = 1;
            }
        }
    }
    int answers[m][n];
    for (int i = m-1; i >= 0; i--) {
        for (int j = n-1; j >= 0; j--) {
            if(i == m-1 && j == n-1){
                answers[i][j] = a[i][j];
            }
            else if(i == m-1){
                if(a[i][j] == a[i][j+1]){
                    answers[i][j] = answers[i][j+1];
                }
                else{
                    if(a[i][j] == 1){
                        answers[i][j] = answers[i][j+1]+1;
                    }
                    else{
                        answers[i][j] = answers[i][j+1];
                    }
                }
            }
            else if(j == n-1){
                if(a[i][j] == a[i+1][j]){
                    answers[i][j] = answers[i+1][j];
                }
                else{
                    if(a[i][j] == 1){
                        answers[i][j] = answers[i+1][j]+1;
                    }
                    else{
                        answers[i][j] = answers[i+1][j];
                    }
                }
            }
            else{
                if(a[i][j] == a[i][j+1]){
                    if(a[i][j] == a[i+1][j]){
                        answers[i][j] = min(answers[i+1][j], answers[i][j+1]);
                    }
                    else{
                        if(a[i][j] == 1){
                            answers[i][j] = min(answers[i+1][j]+1, answers[i][j+1]);    
                        }
                        else{
                            answers[i][j] = min(answers[i+1][j], answers[i][j+1]);
                        }
                    }
                }else{
                   if(a[i][j] == a[i+1][j]){
                       if(a[i][j] == 1){
                            answers[i][j] = min(answers[i+1][j], answers[i][j+1] + 1);   
                       }
                        else{
                            answers[i][j] = min(answers[i+1][j], answers[i][j+1]);
                        }
                    }
                    else{
                        if(a[i][j] == 1){
                            answers[i][j] = min(answers[i+1][j]+1, answers[i][j+1] + 1);    
                        }else{
                          answers[i][j] = min(answers[i+1][j], answers[i][j+1]);  
                        }
                        
                    } 
                }
            }
        }
    }
    std::cout << answers[0][0] << std::endl;
    return 0;
}


Measured memory_bytes: 384