#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const int INF = 999999999;




int N,M,c_f,c_b,H,W;
string s[105];





queue<pll>task,brack;

long long int turn=0,res[130][130];
int main()
{
    cout << fixed << setprecision(18);
    cin>>H>>W;
    
    for(long long int i = 0; i < H; i++){
        for(long long int j = 0; j < W; j++){
            res[i][j]=INF;
        }
    }

    for(long long int i = 0; i < H; i++){
        cin>>s[i];
    }
    
    long long int now=0;
    if(s[0][0]=='#'){
        turn=1;
        brack.push({0,0});
        now++;
    }else{
        turn=0;
        task.push({0,0});
    }

    while(!brack.empty()||!task.empty()){
        if(turn==0){
            long long int fir=task.front().first,sec=task.front().second;
            if(task.front().first<0||task.front().second<0||task.front().first>=H||task.front().second>=W||res[task.front().first][task.front().second]!=INF){
                task.pop();
                if(task.empty()){turn=1;now++;}
                continue;
            }
            res[fir][sec]=now;
            if(sec+1<W){
                if(s[fir][sec+1]=='#'){
                    brack.push({fir,sec+1});
                }else{
                    task.push({fir,sec+1});
                }
            }

            if(fir+1<H){
                if(s[fir+1][sec]=='#'){
                    brack.push({fir+1,sec});
                }else{
                    task.push({fir+1,sec});
                }
            }
            task.pop();
            if(task.empty()){turn=1;now++;}
        }else{
            long long int fir=brack.front().first,sec=brack.front().second;
            if(fir<0||sec<0||fir>=H||sec>=W||res[fir][sec]!=INF){
                brack.pop();
                if(brack.empty()){turn=0;}
                continue;
            }
            res[fir][sec]=now;
            if(sec+1<W){
                if(s[fir][sec+1]=='#'){
                    brack.push({fir,sec+1});
                }else{
                    task.push({fir,sec+1});
                }
            }

            if(fir+1<H){
                if(s[fir+1][sec]=='#'){
                    brack.push({fir+1,sec});
                }else{
                    task.push({fir+1,sec});
                }
            }
            brack.pop();
            if(brack.empty()){turn=0;}
        }
    }
    cout<<res[H-1][W-1]<<endl;
   // DEBUG_OUTPUT_ARRAY2_BOX(s,H,W);
}


Measured memory_bytes: 384