/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll n, m, k, i, j, x, y, p=0, h, f=0;
    vs v;
    string s;
    cin>>n>>m;
    for(i=0; i<n; i++){
        cin>>s;
        v.push_back(s);
    }
    ll a[n][m];
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            if(i==0 && j==0){
                if(v[i][j]=='#'){
                    a[i][j]=1;
                }
                else{
                    a[i][j]=0;
                }
            }
            else if(i==0){
                if(v[i][j-1]=='#')a[i][j]=a[i][j-1];
                else{
                    if(v[i][j]=='#')a[i][j]=a[i][j-1]+1;
                    else a[i][j]=a[i][j-1];
                }
            }
            else if(j==0){
                if(v[i-1][j]=='#')a[i][j]=a[i-1][j];
                else{
                    if(v[i][j]=='#')a[i][j]=a[i-1][j]+1;
                    else a[i][j]=a[i-1][j];
                }
            }
            else{
                if(a[i-1][j]==a[i][j-1]){
                    if(v[i][j]=='#'){
                        if(v[i-1][j]=='#' || v[i][j-1]=='#'){
                            a[i][j]=a[i-1][j];
                        }
                        else{
                            a[i][j]=a[i-1][j]+1;
                        }
                    }
                    else{
                        a[i][j]=a[i-1][j];
                    }
                }
                else if(a[i-1][j]<a[i][j-1]){
                    if(v[i][j]=='#'){
                        if(v[i-1][j]=='#'){
                            a[i][j]=a[i-1][j];
                        }
                        else{
                            a[i][j]=a[i-1][j]+1;
                        }
                    }
                    else{
                        a[i][j]=a[i-1][j];
                    }
                }
                else{
                    if(v[i][j]=='#'){
                        if(v[i][j-1]=='#'){
                            a[i][j]=a[i][j-1];
                        }
                        else{
                            a[i][j]=a[i][j-1]+1;
                        }
                    }
                    else{
                        a[i][j]=a[i][j-1];
                    }
                }
            }
        }
    }
    cout<<a[n-1][m-1]<<endl;
    return 0;
}



Measured memory_bytes: 3712